Using java to create a dynamic rich:panelMenu
- by Mark Lewis
Hail
This attempt at using component libs to access a Map<String, ArrayList<String>>
<rich:panelMenu style="width:35%" mode="ajax"
iconExpandedTopGroup="/img/logListIcon.png"
iconCollapsedTopGroup="/img/logListIcon.png"
iconCollapsedGroup="/img/logListFolderIconClosed.png"
iconExpandedGroup="/img/logListFolderIconOpen.png"
iconGroupTopPosition="left" iconItem="/img/logFileIcon.png">
<!-- feed iteration -->
<ui:repeat items="#{PanelMenu.panelNodes}" var="map">
<rich:panelMenuGroup label="#{map.key}"
style="padding-left: 20px;">
<ui:repeat items="${map.value}" var="entry">
<rich:panelMenuItem label="#{entry}"
action="#{PanelMenu.updateCurrent}">
<f:param name="current" value="#{entry}" />
</rich:panelMenuItem>
</ui:repeat>
</rich:panelMenuGroup>
</ui:repeat>
</rich:panelMenu>
<rich:panel style="width:65%"
bodyClass="rich-laguna-panel-no-header">
<a4j:outputPanel ajaxRendered="true">
<h:outputText value="#{PanelMenu.currentLog}" id="current" />
</a4j:outputPanel>
</rich:panel>
resulted in
|STDOUT| 2010-03-06 22:46:22,212 | ERROR | [http-8181-2]: Exception in the filter chain
javax.servlet.ServletException: com.sun.facelets.component.UIRepeat cannot be cast to org.richfaces.component.UIPanelMenuItem
so I think I need to get onto a resource to use
FacesContext context = FacesContext.getCurrentInstance();
but as I'm fairly new to both java and jsf I need a bit of help. Can anyone suggest either the (probably small) java method to represent this intention or a really good resource specifically about programming dynamic stuff in RichFaces using java?
Naturally I've read the javadocs, but they don't give me a concrete example of some JSF, the associated backing bean java code, and a screen shot of the resulting component.
It may be asking a bit much, but I'm sure I'm not alone in thinking that with these three, I'd be able to understand the idea and apply it to many other component types in this family.
The RF demo doesn't include dynamic panelMenus or drop downs so I'm a bit stumped.
Thanks IA
EDIT
@BalusC: Thanks for the response, here is complete stack trace:
07-Mar-2010 19:05:52 com.sun.facelets.FaceletViewHandler handleRenderException
SEVERE: Error Rendering View[/index.xhtml]
java.lang.ClassCastException: com.sun.facelets.component.UIRepeat cannot be cast to org.richfaces.component.UIPanelMenuItem
at org.richfaces.renderkit.html.PanelMenuRenderer.insertScript(PanelMenuRenderer.java:141)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:260)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:271)
at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:266)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:261)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:106)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:265)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:254)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
07-Mar-2010 19:05:52 com.sun.faces.lifecycle.Phase doPhase
SEVERE: JSF1054: (Phase ID: RENDER_RESPONSE 6, View ID: /index.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@30f369]
07-Mar-2010 19:05:52 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.ClassCastException: com.sun.facelets.component.UIRepeat cannot be cast to org.richfaces.component.UIPanelMenuItem
at org.richfaces.renderkit.html.PanelMenuRenderer.insertScript(PanelMenuRenderer.java:141)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:260)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:271)
at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:266)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:261)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:106)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:265)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:254)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
|STDOUT| 2010-03-07 19:05:52,683 | ERROR | [http-8181-1]: Exception in the filter chain
javax.servlet.ServletException: com.sun.facelets.component.UIRepeat cannot be cast to org.richfaces.component.UIPanelMenuItem
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: com.sun.facelets.component.UIRepeat cannot be cast to org.richfaces.component.UIPanelMenuItem
at org.richfaces.renderkit.html.PanelMenuRenderer.insertScript(PanelMenuRenderer.java:141)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:260)
at org.richfaces.renderkit.html.HtmlPanelMenuRenderer.doEncodeEnd(HtmlPanelMenuRenderer.java:271)
at org.ajax4jsf.renderkit.RendererBase.encodeEnd(RendererBase.java:134)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.TabRendererBase.encodeChildren(TabRendererBase.java:113)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:266)
at org.richfaces.renderkit.html.TabPanelRenderer.doEncodeChildren(TabPanelRenderer.java:261)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:106)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)
at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:265)
at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:254)
at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
... 18 more