RE: Newbee - How to create a dynamic menu in a Struts Action?

"Matt Raible" <lists-T7vlz3gD7BdF/EzeuO4KJwC/[email protected]>
Newsgroups gmane.comp.java.struts-menu.user
Organization Raible Designs, Inc.
Message-ID <[email protected]>
I'd put it into the request.
 
request.setAttribute("repository", repository);
 
Note that you'll have to do this every time you want to view the page
since the repository will disappear once the page is done loading.  You
could also put it into the user's session and then it would stay there
for duration of their session - however long you have that set to.
 
Matt

-----Original Message-----
From: struts-menu-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
[mailto:struts-menu-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org] On Behalf Of
Thomas Bednarz
Sent: Friday, June 25, 2004 2:22 AM
To: Struts menu user list
Subject: [struts-menu] Newbee - How to create a dynamic menu in a Struts
Action?


Hi,

I usually work with Velocity and not with JSP. However I decided to
build my menu with JSP and mix Velocity and JSP. The problem is, that I
have no experience with JSP.

To create a dynamic menu I looked at the database sample. I have the
following question:

How can I put my menu repository from a Struts Action into a JSP Page
Context ?????

I have a Struts Action that builds the menu as follows:

    public ActionForward perform(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
HttpServletResponse response)
    throws IOException, ServletException
    {
        ActionForward af = super.perform(mapping, form, request,
response);
        if (af != null)
            return af;
        ........
        buildMenu(session);
        .....
        return (new ActionForward("/Templates/Test.jsp"));
    }
    
    protected void buildMenu(HttpSession session)
    {
        MenuRepository repository = new MenuRepository();
        MenuRepository defaultRepository = (MenuRepository)
 
session.getServletContext().getAttribute(MenuRepository.MENU_REPOSITORY_
KEY);
        repository.setDisplayers(defaultRepository.getDisplayers());
        
        MenuComponent mc = new MenuComponent();
        mc.setName("Test Menu 1");
        String title = "Menu Title";
        mc.setTitle(title);
        //mc.setLocation("location");
        repository.addMenu(mc);
        
       // WHERE TO PUT THE REPOSITORY OBJECT (IN WHICH CONTEXT??)
       // I should do something like
JSPPageContext.setAttribute("reporsitory", repository);
    }

In the Test.jsp I would like do do something like:

    <menu:useMenuDisplayer name="ListMenu" repository="repository">
        <menu:displayMenu name="Test_Menu_1"/>
    </menu:useMenuDisplayer>    

Many thanks for your help!

Tom.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.