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]



Reply via email to