Re: Newbee - How to create a dynamic menu in a Struts Action?
Thomas Bednarz <[email protected]>
| Newsgroups | gmane.comp.java.struts-menu.user |
|---|---|
| Message-ID | <[email protected]> |
Matt Raible wrote:
> If you're using the same name as the default - you don't need to
> specify the "repository" attribute. That's only needed if you give
> the repository a different name.
>
> Matt
Ahhh! Works fine with that correction now :-). Thanks a lot!
Tom
>
> On Jun 25, 2004, at 8:50 AM, Thomas Bednarz wrote:
>
>> Matt Raible wrote:
>>
>> Yes, it looks in all contexts - so if you put it in any of them it
>> should work. The one from reading menu-config.xml gets put in
>> application, allowing you to customize at the different levels/scopes.
>>
>> Matt
>>
>>
>> Matt,
>>
>> Thanks for your help. But it seems not really to work for me! :-(
>> Hmmm, I did the following in my Struts-Action:
>>
>>
>> session.getServletContext().setAttribute(MenuRepository.MENU_REPOSITORY
>> _KEY, repository);
>> and I also tried
>> session.setAttribute(MenuRepository.MENU_REPOSITORY_KEY,
>> repository);
>>
>> In the JSP I removed:
>> <%
>> pageContext.setAttribute("repository",
>> (MenuRepository)application.getAttribute(MenuRepository.MENU_REPOSITORY
>> _KEY));
>> %>
>>
>> so there remains simply:
>>
>> <menu:useMenuDisplayer name="CoolMenu4" repository="repository">
>> <menu:displayMenu name="WNT"/>
>> <menu:displayMenu name="AD"/>
>> <menu:displayMenu name="Tools"/>
>> <menu:displayMenu name="Info"/>
>> <menu:displayMenu name="Home"/>
>> </menu:useMenuDisplayer>
>>
>> The result is an exception:
>>
>> 2004-06-25 16:44:34 ApplicationDispatcher[/Echnaton]
>> Servlet.service() for servlet jsp threw exception
>> javax.servlet.jsp.JspException: The menu repository could not be found.
>> at
>> net.sf.navigator.taglib.UseMenuDisplayerTag.doStartTag(UseMenuDisplayer
>> Tag.java:148)
>> at
>> org.apache.jsp.Templates.EWCHeader_jsp._jspx_meth_menu_useMenuDisplayer
>> _0(EWCHeader_jsp.java:181)
>> at
>> org.apache.jsp.Templates.EWCHeader_jsp._jspService(EWCHeader_jsp.java:
>> 132)
>> at
>> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
>> ......
>>
>> Any idea what I am missing?
>>
>> Tom
>>
>>
>> On Jun 25, 2004, at 8:05 AM, Thomas Bednarz wrote:
>>
>>
>> Matt Raible wrote:
>>
>> 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
>>
>> Matt,
>>
>> I found a different, maybe less elegant solution to that:
>>
>> In the Struts-Action I put the stuf f in the application context:
>>
>>
>> session.getServletContext().setAttribute(MenuRepository.MENU_REPOSITORY
>> _KEY, repository);
>>
>> In the Jsp I take it from the application context:
>>
>> <%
>> pageContext.setAttribute("repository",
>> (MenuRepository)application.getAttribute(MenuRepository.MENU_REPOSITORY
>> _KEY));
>> %>
>> At least this works fine but may not be efficient.
>>
>> What I do not understand: (Just for a better understanding how it
>> works behind the scenes)
>>
>> <menu:useMenuDisplayer name="CoolMenu4" repository="repository">
>> .........
>> </menu:useMenuDisplayer>
>>
>> Where does it look for the "repository" object? Does it lookup in
>> all contexts (Page, Request, Session, Application)?
>>
>> Cheers
>>
>> Tom
>>
>> -----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.
>>
>>
>>
>>
>>
>>
>>
>> -------------------------------------------------------
>> This SF.Net email sponsored by Black Hat Briefings & Training.
>> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
>> digital self defense, top technical experts, no vendor pitches,
>> unmatched networking opportunities. Visit www.blackhat.com
>> _______________________________________________
>> struts-menu-user mailing list
>> struts-menu-user-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>>
>>
>>
>>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital
> self defense, top technical experts, no vendor pitches, unmatched
> networking opportunities. Visit www.blackhat.com
> _______________________________________________
> struts-menu-user mailing list
> struts-menu-user-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/struts-menu-user
>
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com