When user clicks the content layout, menu layout keeps unchanged.
Therefore I do not add an action entry in struts-config.xml
After adding controllerClass in tiles-defs.xml, no errors display and
menu layout on the left does not display testing value as I want.
It seems that the controllerClass inside menu layout is not triggerred,
after the content layout is changed.
tiles-defs.xml:
<definition name="erp.menu.home" path="/layout/menu.jsp"
controllerClass="com.common.tiles.MyMenuAction" >
<put name="title" value="Tiles" />
<putList name="items" >
<item value="customize1" link="/Welcome1.jsp" />
<item value="customize2" link="/Welcome2.jsp" />
</putList>
</definition>
controllerClass:
public class MyMenuAction extends ControllerSupport {
public void execute(ComponentContext tileContext,
HttpServletRequest request,
HttpServletResponse response,
ServletContext context)
throws Exception {
List menuItems = (List) context.getAttribute("items");
menuItems.add("test_1");
menuItems.add("test_2");
tileContext.putAttribute("items", menuItems);
}
}
On Wed, 27 Oct 2004 17:50:02 +0200, Mark Lowe <[EMAIL PROTECTED]> wrote:
> What are you trying to do have a constant navigation system?
>
> TilesAction is like Action except it has the tiles context aviable
> giving easy access to values in you tiles defs.
>
> TilesControllers let you do stuff to tiles defs before an action.
>
> You current code should work if you map the action (remove the
> implements Controller) and map it
>
> <action path="/myaction" class="com.packagename.MyAction" />
>
> and then call it in your tiles def
>
> <definition name="mydef" controllerUrl="/myaction.do" ..
>
> at least i think so.
>
> Alternatively the example i gave you of a controller would be
>
> <definition name="mydef" controllerClass="com.packagename.MyController">
> ..
>
> he problem with controllers is that its hard to handle exceptions..
> But if you're not doing anything that clever in there then perhaps
> you'd deem that as okay.
>
>
>
> Mark
>
> On Wed, 27 Oct 2004 23:41:07 +0800, PC Leung <[EMAIL PROTECTED]> wrote:
> > Mark,
> >
> > It is my 1st trial of using Tiles.
> > I do not know how to choose. What are you using?
> > Could you show me some fragment codes with
> > struts-defs.xml,
> > struts-config.xml
> > action or controllerSomething?
> >
> > Thanks
> >
> >
> >
> >
> > On Wed, 27 Oct 2004 17:26:55 +0200, Mark Lowe <[EMAIL PROTECTED]> wrote:
> > > Decide if you want to use an action or a tiles controller.. Or a tiles action..
> > >
> > > You can use an action if you return null rather than a forward (well
> > > for a forward) and use the controllor url attribute. But this means
> > > wiring an an action and a tile/ controllorUrl="/myaction.do"
> > >
> > > Mark
> > >
> > >
> > >
> > > On Wed, 27 Oct 2004 23:22:03 +0800, PC Leung <[EMAIL PROTECTED]> wrote:
> > > > Error messages display as follows.
> > > >
> > > > [ServletException in:/layout/menu.jsp] null'
> > > > java.lang.ClassCastException at
> > > > org.apache.jsp.layout.menu_jsp._jspService(menu_jsp.java:193) at
> > > > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
> > > > ...
> > > > ...
> > > >
> > > > after adding a few lines to test in the following class,
> > > >
> > > > public final class MyMenuAction extends TilesAction implements Controller {
> > > > public ActionForward perform( ComponentContext context,
> > > > ActionMapping mapping,
> > > > ActionForm form,
> > > > HttpServletRequest request,
> > > > HttpServletResponse response)
> > > > throws IOException, ServletException {
> > > > perform( context, request, response, getServlet().getServletContext() );
> > > > return null;
> > > > }
> > > > public void perform(ComponentContext context,
> > > > HttpServletRequest request, HttpServletResponse
> > > > response,
> > > > ServletContext servletContext)
> > > > throws ServletException, IOException {
> > > > List menuItems = (List) context.getAttribute("items"); //
> > > > menuItems.add("customize1");
> > > > // this few lines
> > > > menuItems.add("customize2"); //
> > > > context.putAttribute("items", menuItems); //
> > > > ...
> > > >
> > > > Struts-defs.xml:
> > > > <definition name="erp.menu.home" path="/layout/menu.jsp"
> > > > controllerClass="com.common.tiles.MyMenuAction" >
> > > > <put name="title" value="Tiles" />
> > > > <putList name="items" >
> > > > <item value="customize1" link="/Welcome1.jsp" />
> > > > <item value="customize2" link="/Welcome2.jsp" />
> > > > </putList>
> > > > </definition>
> > > >
> > > > How can I add a few lines of creating a list to test the menu?
> > > >
> > > > Thanks
> > > >
> > > > On Tue, 26 Oct 2004 19:57:49 +0200, Mark Lowe <[EMAIL PROTECTED]> wrote:
> > > > > To do what you want you want a tiles controller, not an action.
> > > > >
> > > > > import org.apache.struts.tiles.ComponentContext;
> > > > > import org.apache.struts.tiles.ControllerSupport;
> > > > > import org.apache.struts.tiles.beans.SimpleMenuItem;
> > > > > import java.util.List;
> > > > > import javax.servlet.ServletContext;
> > > > > import javax.servlet.ServletException;
> > > > > import javax.servlet.http.HttpServletRequest;
> > > > > import javax.servlet.http.HttpServletResponse;
> > > > > import javax.servlet.http.HttpSession;
> > > > >
> > > > > public class GroupController extends ControllerSupport {
> > > > > public void execute(ComponentContext tileContext,
> > > > > HttpServletRequest request, HttpServletResponse response,
> > > > > ServletContext context) throws Exception {
> > > > >
> > > > > List menuItems = (List) context.getAttribute("items");
> > > > >
> > > > > .. add some menu items.
> > > > >
> > > > > context.putAttribute("items", menuItems);
> > > > > }
> > > > > }
> > > > >
> > > > > I;d try and avoid using a tiles controller as exception handling is an
> > > > > arse. Perhaps look at having a BaseAction that adds teh relevant items
> > > > > into the request.
> > > > >
> > > > > public abstract class BaseAction extends Action {
> > > > >
> > > > > protected abstract ActionForward doExecute(ActionMapping mapping,
> > > > > ActionForm form, HttpServletRequest request,
> > > > > HttpServletResponse response) throws Exception;
> > > > >
> > > > > public ActionForward execute(ActionMapping mapping, ActionForm form,
> > > > > HttpServletRequest request, HttpServletResponse response)
> > > > > throws Exception {
> > > > > ..
> > > > > request.setAttribute("items",menuItems); // perhaps
> > > > > application scope
> > > > >
> > > > > return doExecute(mapping, form, request, response);
> > > > > }
> > > > > }
> > > > >
> > > > > Now execute will be run for ever class that subclasses it, and they
> > > > > will have to use the doExecute(), method.. For more details check the
> > > > > xpetstore project out that uses this technique. This approach will
> > > > > allow you to make use of exception handlers.
> > > > >
> > > > > Mark
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > On 26 Oct 2004, at 17:14, PC Leung wrote:
> > > > >
> > > > > > Hello world,
> > > > > >
> > > > > > The following is a fragment of tiles-defs.xml.
> > > > > > where MyMenuAction actually is UserMenuAction in Tiles.
> > > > > >
> > > > > > <definition name="erp.menu.home" path="/layout/menu.jsp"
> > > > > > controllerClass="com.common.tiles.MyMenuAction" >
> > > > > > <put name="title" value="Tiles" />
> > > > > > <putList name="items" >
> > > > > > <item value="customize" link="/Welcome.jsp" />
> > > > > > ^^^^^^^^^^ ^^^^^^^^^^^^^^^
> > > > > > </putList>
> > > > > > </definition>
> > > > > >
> > > > > > Where and how should I put the coding inside MyMenuAction
> > > > > > so that I can add a number of items which behaves as
> > > > > > a list of menu item?
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > For additional commands, e-mail: [EMAIL PROTECTED]
> > > >
> > > >
> > >
> >
> > ---------------------------------------------------------------------
> >
> >
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]