1 2 Previous Next 15 Replies Latest reply on Apr 7, 2012 5:24 AM by Matteo Mancini

    Panelmenuitem actions in binding bean not responding

    Bryan Cantu Newbie

      Hello all,
      I am attempting to code a bean to render a panel menu and dynamically build groups and panelmenuitems. I have used one of the example jsp's I found and have been editing this to build my bean. The following represents that part of the example jsp with tags that I'm trying to code in my bean. I have tried many variations of the action but it doesn't seam to respond at all... the leftMenu.updateCurrent doesn't happen

      eg.

      <rich:panelMenuItem label="Item 1.2" action="#{leftMenu.updateCurrent}"
       onclick="document.location.href='http://AqueousIt01:2345/aqueousIt.faces?chapter=chapter2'">
       <h:outputLink value="http://AqueousIt01:2345/aqueousIt.faces?chapter=chapter2">
       <h:outputText value="Chapter 2"></h:outputText>
       </h:outputLink>
       <f:param name="current" value="Item 1.2"/>
       <f:param name="chapter" value="chapter2"/>
      </rich:panelMenuItem>


      1) My last attempts failed because the action was not working.
      2) I was having difficulty coding the output link,
      3) And the parameters I'm just haven't registered as to how to code these...

      My attempted code looks like this...

      HtmlPanelMenuItem[] pMenuItms = (HtmlPanelMenuItem[]) Array.newInstance(HtmlPanelMenuItem.class,12);
       MethodExpression[] pMenuEL = (MethodExpression[]) Array.newInstance(MethodExpression.class,12);
       ValueExpression[] pMenuVE1 = (ValueExpression[]) Array.newInstance(ValueExpression.class,12);
      
       for (int i = 0; i < 12; i++) {
       System.out.println("Loop count: " + i);
       pMenuItms = (HtmlPanelMenuItem) app.createComponent(HtmlPanelMenuItem.COMPONENT_TYPE);
       pMenuItms.setName("B1Chapter" + (i+1));
       pMenuItms.setId("B1Chapter" + (i+1));
       pMenuItms.setLabel("Chapter " + (i+1));
      
       pMenuItms.setOnclick("document.location.href='http://AqueousIt01:2345/aqueousIt.faces?chapter=chapter"+ (i+1) +"'");
       pMenuEL = app.getExpressionFactory().createMethodExpression(FacesContext.getCurrentInstance().getELContext(),
       "#{lpanMenu.updateCurrent}", null, new Class<?>[0]);
      
      pMenuItms.setActionExpression(pMenuEL);
      
      
      pMenuItms.setValueExpression("chapter",app.getExpressionFactory().createValueExpression("chapter"+ (i+1) ,String.class));
      
       pMenuItms.setValueExpression("current",app.getExpressionFactory().createValueExpression("Item "+ (i+1) ,String.class));
      
      
      pMenuVE1 = app.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "Item1.1", java.lang.String.class);
      
       pMenuItms.setValueExpression("current",pMenuVE1);
      
       pMenuVE1 = app.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(),"chapter", java.lang.String.class);
      
      
      pMenuItms.addActionListener(new ActionListener(){ public void processAction(final ActionEvent event) {
      
       System.out.println("process action: updateCurrent(event);");
       LeftMenu lmb = (LeftMenu)event.getComponent().getAttributes().get("lpanMenu");
       lmb.updateCurrent(event);
       }
       } );
       pmg.getChildren().add(pMenuItms);
       }
      ....
      
      
       public String updateCurrent() {
       FacesContext context=FacesContext.getCurrentInstance();
      
       setCurrent((String)context.getExternalContext().getRequestParameterMap().get("current"));
       setChapter((String)context.getExternalContext().getRequestParameterMap().get("chapter"));
       return null;
       }
      
      
       public void updateCurrent(ActionEvent event) {
       setCurrent(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
       setChapter(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
       }
      


      If anyone could offer some advise it would be greatly appreciated.
      I think I've got something really wrong...


        • 1. Re: Panelmenuitem actions in binding bean not responding
          Rangel Preis Newbie

          I have the same problem i try this:

           FacesContext fc = FacesContext.getCurrentInstance();
           ELContext el = fc.getELContext();
           MethodExpression me = fc.getApplication().getExpressionFactory().createMethodExpression(el, "#{panelMenu.myAction}", null, new Class[0]);
           menuItem1.setActionExpression(me);
          
          .............
          
           public void myAction(){
           System.out.println("Testing");
           }
          


          The output:


          SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@183aedf]
          11/04/2008 07:45:31 org.apache.catalina.core.StandardWrapperValve invoke
          SEVERE: Servlet.service() for servlet Faces Servlet threw exception
          java.lang.IllegalStateException: com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu$1
          at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:109)
          at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1428)
          at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1293)
          at javax.faces.component.UICommand.restoreState(UICommand.java:337)
          at org.richfaces.component.html.HtmlPanelMenuItem.restoreState(HtmlPanelMenuItem.java:1336)
          at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1161)
          at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
          at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
          at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
          at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
          at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:235)
          at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
          at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:116)
          at org.ajax4jsf.application.AjaxViewHandler.restoreView(AjaxViewHandler.java:131)


          Any solution?

          • 2. Re: Panelmenuitem actions in binding bean not responding
            Nick Belaevski Master

             

            "rangelp" wrote:
            I have the same problem i try this:

             FacesContext fc = FacesContext.getCurrentInstance();
             ELContext el = fc.getELContext();
             MethodExpression me = fc.getApplication().getExpressionFactory().createMethodExpression(el, "#{panelMenu.myAction}", null, new Class[0]);
             menuItem1.setActionExpression(me);
            
            .............
            
             public void myAction(){
             System.out.println("Testing");
             }
            


            The output:


            SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@183aedf]
            11/04/2008 07:45:31 org.apache.catalina.core.StandardWrapperValve invoke
            SEVERE: Servlet.service() for servlet Faces Servlet threw exception
            java.lang.IllegalStateException: com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu$1
            at javax.faces.component.StateHolderSaver.restore(StateHolderSaver.java:109)
            at javax.faces.component.UIComponentBase.restoreAttachedState(UIComponentBase.java:1428)
            at javax.faces.component.UIComponentBase.restoreState(UIComponentBase.java:1293)
            at javax.faces.component.UICommand.restoreState(UICommand.java:337)
            at org.richfaces.component.html.HtmlPanelMenuItem.restoreState(HtmlPanelMenuItem.java:1336)
            at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1161)
            at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
            at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
            at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
            at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:1177)
            at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:235)
            at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:316)
            at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:116)
            at org.ajax4jsf.application.AjaxViewHandler.restoreView(AjaxViewHandler.java:131)


            Any solution?


            Do you have com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu$1 class public & static so that state manager can create a new instance?

            • 3. Re: Panelmenuitem actions in binding bean not responding
              Nick Belaevski Master

              You should set mode="none" for panel menu item if you wish to use nested h:outputLink: http://livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf. Note that in such case action & actionListener attributes will be ignored.

              • 4. Re: Panelmenuitem actions in binding bean not responding
                Rangel Preis Newbie

                 


                Do you have com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu$1 class public & static so that state manager can create a new instance?


                PanelMenu is a public class. I don't understand why you say static.

                I can't fire any action...
                Anyone can help with PanelMenu and dynamic actions?

                • 5. Re: Panelmenuitem actions in binding bean not responding
                  Rangel Preis Newbie

                   


                  You should set mode="none" for panel menu item if you wish to use nested h:outputLink: http://livedemo.exadel.com/richfaces-demo/richfaces/panelMenu.jsf . Note that in such case action & actionListener attributes will be ignored.


                  I set mode="server" or mode="ajax".......


                  Do you have com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu$1 class public & static so that state manager can create a new instance?


                  My class is public and all methods is public too.

                  Anyone set a dynamic action in the paneLMenu???? Any help?

                  Thanks

                  • 6. Re: Panelmenuitem actions in binding bean not responding
                    Ilya Shaikovsky Master

                    rangelp, you should use mode=none in order to use your own links inside. anyway please post you page code also.

                    • 7. Re: Panelmenuitem actions in binding bean not responding
                      Rangel Preis Newbie

                      Thanks for your time, here is my code:

                      JSP page

                      <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
                      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
                      <%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
                      
                      <f:view>
                       <h:form>
                       <table width="200">
                       <tr>
                       <td><table width="200">
                       <tr>
                       <td><a4j:commandLink value="Administrativo" action="#{panelMenu.criaMenu1}" reRender="menu"/></td>
                       <td><a4j:commandLink value="Financeiro" action="#{panelMenu.criaMenu2}" reRender="menu"/></td>
                       </tr>
                       <tr>
                       <td>
                       <br>
                       <br>
                       <br>
                       <br>
                       <br>
                       </td>
                       </tr>
                       </table>
                       <table width="200">
                       <tr>
                      
                       <td>
                       <rich:panelMenu id="menu" binding="#{panelMenu.menu2}" mode="none"/>
                       </td>
                       <td> </td>
                       </tr>
                       </table>
                       </td>
                       </tr>
                       </table>
                       </h:form>
                      </f:view>
                      


                      Back Bean code
                      import javax.el.ELContext;
                      import javax.el.ExpressionFactory;
                      import javax.el.MethodExpression;
                      import javax.faces.application.Application;
                      import javax.faces.context.FacesContext;
                      import javax.faces.event.ActionEvent;
                      i
                      import org.richfaces.component.html.HtmlPanelMenu;
                      import org.richfaces.component.html.HtmlPanelMenuGroup;
                      import org.richfaces.component.html.HtmlPanelMenuItem;
                      
                      public class PanelMenu {
                      
                       private HtmlPanelMenu menu2;
                      
                      
                       public void criaMenu1(){
                       if (this.menu2 == null){
                       this.menu2 = new HtmlPanelMenu();
                       } else {
                       this.menu2.getChildren().clear();
                       }
                      
                       HtmlPanelMenuGroup grupo1 = new HtmlPanelMenuGroup();
                       grupo1.setName("Grupo1");
                       grupo1.setLabel("Grupo1 - ADM");
                      
                       HtmlPanelMenuGroup grupo2 = new HtmlPanelMenuGroup();
                       grupo2.setName("Grupo2");
                       grupo2.setLabel("Grupo2 - ADM");
                      
                       HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
                       menuItem1.setId("menuItem1");
                       menuItem1.setName("Cadastrar");
                       menuItem1.setLabel("Cadastrar");
                       menuItem1.setMode("server");
                      
                       HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
                       menuItem2.setId("menuItem2");
                       menuItem2.setName("Consultar");
                       menuItem2.setLabel("Consultar");
                      
                       Application facesApp = FacesContext.getCurrentInstance().getApplication();
                       ELContext elContext = FacesContext.getCurrentInstance().getELContext();
                       ExpressionFactory expressionFactory = facesApp.getExpressionFactory();
                      
                       MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, "#{panelMenu.myAction}", null, new Class[] {ActionEvent.class});
                      
                       menuItem2.setActionExpression(methodExpression);
                       menuItem2.setMode("server");
                      
                       HtmlPanelMenuItem menuItem3 = new HtmlPanelMenuItem();
                       menuItem3.setName("Item2");
                       menuItem3.setLabel("Item 2.1");
                       menuItem3.setMode("server");
                      
                       HtmlPanelMenuItem menuItem4 = new HtmlPanelMenuItem();
                       menuItem4.setName("Item3");
                       menuItem4.setLabel("Item 2.2");
                       menuItem4.setMode("server");
                      
                       grupo1.getChildren().add(menuItem1);
                       grupo1.getChildren().add(menuItem2);
                      
                       grupo2.getChildren().add(menuItem3);
                       grupo2.getChildren().add(menuItem4);
                      
                       this.menu2.getChildren().add(grupo1);
                       this.menu2.getChildren().add(grupo2);
                      
                       }
                      
                       public void myAction(){
                       System.out.println("Menuitem2 action2");
                       }
                      
                       public void myEvent(ActionEvent event){
                       System.out.println("BBBBBBBBBBBBBBBBB");
                      
                       }
                      
                       public void criaMenu2(){
                       if (this.menu2 == null){
                       this.menu2 = new HtmlPanelMenu();
                       } else {
                       this.menu2.getChildren().clear();
                       }
                      
                       HtmlPanelMenuGroup grupo1 = new HtmlPanelMenuGroup();
                       grupo1.setName("Grupo1");
                       grupo1.setLabel("Grupo1 - FIN");
                      
                       //menuGroup.
                      
                       HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
                       menuItem1.setName("Cadastrar");
                       menuItem1.setLabel("Cadastrar");
                      
                       HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
                       menuItem2.setName("Consultar");
                       menuItem2.setLabel("Consultar");
                      
                       grupo1.getChildren().add(menuItem1);
                       grupo1.getChildren().add(menuItem2);
                      
                       menu2.getChildren().add(grupo1);
                      
                       }
                      
                       public HtmlPanelMenu getMenu2() {
                       return menu2;
                       }
                      
                       public void setMenu2(HtmlPanelMenu menu2) {
                       this.menu2 = menu2;
                       }
                      }
                      


                      • 8. Re: Panelmenuitem actions in binding bean not responding
                        Bryan Cantu Newbie

                        Hi all,
                        Thanks to the last few postings nearly everything is working except the ActionListener. I have been reading that others have also had problems...
                        I'm using version 3.2.0 SP1.

                        It could be that I'm a little confused. Looking at the samples the JSP uses a bean that has coded,

                        JSP.

                         <rich:panelMenuGroup label="Group 1">
                        
                         <rich:panelMenuItem label="Item 1.1" action="#{panelMenu.updateCurrent}">
                        
                         <f:param name="current" value="Item 1.1"/>
                        
                         </rich:panelMenuItem>
                        
                        


                        Binding Bean
                        public void updateCurrent(ActionEvent event) {...
                        


                        but this it isn't referenced in the JSP other than the action="#{leftMenu.updateCurrent}". How is it this method is called with the ActionEvent parameter, eg updateCurrent(ActionEvent event) ... I missed something? I have debuged the method is called with the ActionEvent parameter executed...

                        I would like to code a bean that also uses the updateCurrent(ActionEvent event) and tried using an ActionListener but it doesn't make sense though.

                        How do I code such a call to a bean in this case...
                        I tried the following and this also would not execute...

                         menuItem2.addActionListener(new ActionListener(){
                         public void processAction(ActionEvent e) {
                         System.out.println("--*made it*--");
                         }
                         });
                        



                        How would I rewrite the above to use an Expression and this would be an actionlistener?
                        eg menuItem2.addActionListener(#{bean.updateCurrent(ActionEvent })
                        If anyone could help out I would greatly appreciate it....
                        Cheers



                        • 9. Re: Panelmenuitem actions in binding bean not responding
                          Antonio Gurisatti Newbie

                          Hi,

                          In your backing bean do this:

                          HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
                          UIParameter param = new UIParameter();
                          param.setName("option");
                          param.setValue("opt1");
                          menuItem1.setName("Cadastrar");
                          menuItem1.setLabel("Cadastrar");
                          menuItem1.setAction(FacesContext.getCurrentInstance().getApplication()
                          .createMethodBinding("#{myBackingBean.processrSelection}", new Classs[0]));
                          menuItem1.getChildren().add(param);
                          
                          


                          This sets the action and f:param for the panelMenuItem.

                          Then, in your action method:

                           public String processSelection() {
                           FacesContext context=FacesContext.getCurrentInstance();
                           System.out.println((String)context.getExternalContext().getRequestParameterMap().get("option"));
                           return null;
                           }
                          
                          


                          This should work for you.

                          Hope this helps you out

                          • 10. Re: Panelmenuitem actions in binding bean not responding
                            Rangel Preis Newbie

                            maguri thanks for your help but the method setAction is deprecated in version 3.2.

                            I try your code and it doesn't work.

                            I use that:


                            MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, "#{panelMenu.myAction}", Void.class, new Class[] {ActionEvent.class});
                            
                            HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
                            menuItem2.setName("Consultar");
                            menuItem2.setLabel("Consultar");
                            
                            menuItem2.setActionExpression(methodExpression);
                            menuItem2.setMode("server");
                            


                            if i use this:
                             public String myAction(){
                             System.out.println("Testing");
                             return null;
                             }
                            


                            I get this error:

                            javax.servlet.ServletException: #{panelMenu.myAction}: javax.el.MethodNotFoundException: Method not found: com.agriness.sandboxjsf.presentation.web.jsf.PanelMenu@e83c97.myAction(javax.faces.event.ActionEvent)
                            javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
                            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
                            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
                            org.ajax4jsf.Filter.doFilter(Filter.java:175)


                            and when i try this
                             public void myAction(ActionEvent event){
                             System.out.println("Testing");
                             }
                            


                            I get this error:

                            javax.servlet.ServletException: wrong number of arguments
                            javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
                            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
                            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
                            org.ajax4jsf.Filter.doFilter(Filter.java:175)


                            Anyone can help? Anyone HAVE a example that WORK?

                            • 11. Re: Panelmenuitem actions in binding bean not responding
                              Bryan Cantu Newbie

                              Thanks for the reply,

                              I have only one problem with the code below (I believe) and that is method below will not fire...

                              public void itemAction(ActionEvent event){
                               System.out.println("itemAction(event)...");
                              
                               setCurrent(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
                               setChapter(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
                              
                               }
                              


                              I need the event parameter to change this beans values 'current' and 'chapter'. These are the parameters defined as children of one of the menuItems... (Get Menu One -> Group1 -> menuitem1 (Action Fired...))

                              Only the following is fired as an Action event:

                              public String itemAction(){
                               System.out.println("itemAction()...");
                               FacesContext context=FacesContext.getCurrentInstance();
                               System.out.println("Chapter Parameter is: "+(String)context.getExternalContext().getRequestParameterMap().get("chapter"));
                               return null;
                               }
                              
                              


                              It could be that I need to pass the event parameter but I don't understand how.

                              I thought the first method above was some how implied and called implicitly. But Why...

                              Because It seems to work that way in the richfaces demo jsp for panelmenues.

                              I have based what I'm trying to do on the examples given here and on the example Demo JSP for the PanelMenu. Where the two methods above are fired although the first above is not coded in the JSP... (see demo jsp)

                              I guess I have two questions how can the first method above be called using the event parameter...

                              The following code is working but will not fire the first method.
                              (most likely because I haven't coded the methodExpession and I don't know how...)

                              JSP:
                               <table width="200">
                               <tr>
                               <td><table width="200">
                               <tr>
                               <td><a4j:commandLink value="Get Menu One" action="#{newLeftMenu.selectedMenu1}" reRender="newlftmenu"/></td>
                               <td><a4j:commandLink value="Get Manu Two" action="#{newLeftMenu.selectedMenu2}" reRender="newlftmenu"/></td>
                               </tr>
                               <tr>
                               <td>
                               <br>
                               <br>
                               <br>
                               <br>
                               <br>
                               </td>
                               </tr>
                               </table>
                               <table width="200">
                               <tr>
                              
                               <td>
                               <rich:panelMenu id="newlftmenu" binding="#{newLeftMenu.selectedMenu}" mode="none"/>
                               <rich:panel>
                              
                               <a4j:outputPanel ajaxRendered="true">
                               <h:outputText value="#{newLeftMenu.current}" id="current"/>
                               </a4j:outputPanel>
                              
                               </rich:panel>
                               </td>
                               <td> </td>
                               </tr>
                               </table>
                               </td>
                               </tr>
                               </table>
                              


                              Faces.config file

                               <managed-bean>
                               <managed-bean-name>newLeftMenu</managed-bean-name>
                               <managed-bean-class>common.menu.left.NewLeftMenu</managed-bean-class>
                               <managed-bean-scope>session</managed-bean-scope>
                               <managed-property>
                               <property-name>current</property-name>
                               <property-class>java.lang.String</property-class>
                               <value>Nothing</value>
                               </managed-property>
                               <managed-property>
                               <property-name>chapter</property-name>
                               <property-class>java.lang.String</property-class>
                               <value>chapter1</value>
                               </managed-property>
                               <managed-property>
                               <property-name>singleMode</property-name>
                               <property-class>java.lang.Boolean</property-class>
                               <value>true</value>
                               </managed-property>
                               </managed-bean>
                              


                              backing bean class NewLeftMenu:

                              
                              
                              package common.menu.left;
                              
                              
                              import javax.el.ELContext;
                              import javax.el.ExpressionFactory;
                              import javax.el.MethodExpression;
                              import javax.el.ValueExpression;
                              import javax.faces.application.Application;
                              import javax.faces.component.UIParameter;
                              import javax.faces.context.FacesContext;
                              import javax.faces.event.AbortProcessingException;
                              import javax.faces.event.ActionEvent;
                              import javax.faces.event.ActionListener;
                              import org.ajax4jsf.component.html.HtmlActionParameter;
                              import org.richfaces.component.UIPanelMenuItem;
                              
                              import org.richfaces.component.html.HtmlPanelMenu;
                              import org.richfaces.component.html.HtmlPanelMenuGroup;
                              import org.richfaces.component.html.HtmlPanelMenuItem;
                              
                              /**
                               *
                               * @author Aqueous
                               */
                              public class NewLeftMenu {
                              
                              
                              
                               /** Creates a new instance of LeftMenu */
                               public NewLeftMenu() {
                               }
                              
                              
                              
                               private HtmlPanelMenu selectedMenu;
                              
                               private String current;
                               private String chapter;
                               private boolean singleMode;
                              
                               public void selectedMenu1(){
                               if (this.selectedMenu == null){
                               this.selectedMenu = new HtmlPanelMenu();
                               this.selectedMenu.setImmediate(true);
                               this.selectedMenu.setRendered(true);
                              
                               } else {
                               this.selectedMenu.getChildren().clear();
                               }
                              
                               HtmlPanelMenuGroup Group1 = new HtmlPanelMenuGroup();
                               Group1.setName("Group1");
                               Group1.setLabel("Group1");
                              
                              
                               HtmlPanelMenuGroup Group2 = new HtmlPanelMenuGroup();
                               Group2.setName("Group2");
                               Group2.setLabel("Group2");
                              
                               HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
                               menuItem1.setId("menuItem1");
                               menuItem1.setName("menuItem1");
                               menuItem1.setLabel("menuItem1 (no action...)");
                               menuItem1.setMode("server");
                              
                              
                               HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
                               menuItem2.setId("menuItem2");
                               menuItem2.setName("menuItem2");
                               menuItem2.setLabel("menuItem1 (action fired...");
                               menuItem2.setMode("server");
                              
                              
                               Application facesApp = FacesContext.getCurrentInstance().getApplication();
                               ELContext elContext = FacesContext.getCurrentInstance().getELContext();
                               ExpressionFactory expressionFactory = facesApp.getExpressionFactory();
                              
                               MethodExpression methodExpression = expressionFactory.createMethodExpression(elContext, "#{newLeftMenu.itemAction}", null, new Class<?>[0]);
                               menuItem2.setActionExpression(methodExpression);
                              
                               UIParameter param1 = new UIParameter();
                               param1.setName("chapter");
                               param1.setValue("chapter3");
                               UIParameter param2 = new UIParameter();
                               param2.setName("current");
                               param2.setValue("Item 9.9");
                              
                               menuItem2.getChildren().add(param1);
                               menuItem2.getChildren().add(param2);
                              
                               HtmlPanelMenuItem menuItem3 = new HtmlPanelMenuItem();
                               menuItem3.setName("Item2");
                               menuItem3.setLabel("Item 2.1");
                               menuItem3.setMode("server");
                              
                               HtmlPanelMenuItem menuItem4 = new HtmlPanelMenuItem();
                               menuItem4.setName("Item3");
                               menuItem4.setLabel("Item 2.2");
                               menuItem4.setMode("server");
                              
                               Group1.getChildren().add(menuItem1);
                               Group1.getChildren().add(menuItem2);
                              
                               Group2.getChildren().add(menuItem3);
                               Group2.getChildren().add(menuItem4);
                              
                               this.selectedMenu.getChildren().add(Group1);
                               this.selectedMenu.getChildren().add(Group2);
                              
                               }
                              
                               public String itemAction(){
                               System.out.println("itemAction()...");
                               FacesContext context=FacesContext.getCurrentInstance();
                               System.out.println("Chapter Parameter is: "+(String)context.getExternalContext().getRequestParameterMap().get("chapter"));
                               return null;
                               }
                              
                              
                              //this does not fire...
                               public void itemAction(ActionEvent event){
                               System.out.println("itemAction(event)...");
                              
                               setCurrent(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
                               setChapter(((UIPanelMenuItem)event.getComponent()).getLabel().toString());
                              
                               }
                              
                              
                               public void selectedMenu2(){
                               if (this.selectedMenu == null){
                               this.selectedMenu = new HtmlPanelMenu();
                               } else {
                               this.selectedMenu.getChildren().clear();
                               }
                              
                               HtmlPanelMenuGroup Group1 = new HtmlPanelMenuGroup();
                               Group1.setName("Group1");
                               Group1.setLabel("Group1");
                              
                               //menuGroup.
                              
                               HtmlPanelMenuItem menuItem1 = new HtmlPanelMenuItem();
                               menuItem1.setName("Item1");
                               menuItem1.setLabel("Item1");
                              
                               HtmlPanelMenuItem menuItem2 = new HtmlPanelMenuItem();
                               menuItem2.setName("Item2");
                               menuItem2.setLabel("Item2");
                              
                              
                              
                               Group1.getChildren().add(menuItem1);
                               Group1.getChildren().add(menuItem2);
                              
                               selectedMenu.getChildren().add(Group1);
                              
                               }
                              
                               public HtmlPanelMenu getSelectedMenu() {
                               return selectedMenu;
                               }
                              
                               public void setSelectedMenu(HtmlPanelMenu selectedMenu) {
                               this.selectedMenu = selectedMenu;
                               }
                              
                              
                              
                               public String getCurrent() {
                               return this.current;
                               }
                              
                               public void setCurrent(String current) {
                               this.current = current;
                               }
                              
                              
                              
                               public String getChapter() {
                               return this.chapter;
                               }
                              
                               public void setChapter(String chapter) {
                               this.chapter = chapter;
                               }
                              
                              
                              
                               public boolean isSingleMode() {
                               return singleMode;
                               }
                              
                               public void setSingleMode(boolean singleMode) {
                               this.singleMode = singleMode;
                               }
                              }
                              
                              



                              Does anyone out there understand how the ActionEvent parameter is passed to the backing bean Action method? When etc...

                              Many thanks

                              • 12. Re: Panelmenuitem actions in binding bean not responding
                                Rangel Preis Newbie

                                Someone have a example that works? A little example of a dymanic panelMenu with dynamic actions?

                                • 13. Re: Panelmenuitem actions in binding bean not responding
                                  Matteo Mancini Newbie

                                  Hi,

                                  my example works, action from menu item is executed ....

                                   

                                  [my page .xhtml]

                                                               <h:form>

                                                                  <rich:panelMenu style="width:200px" itemMode="server" groupMode="client"

                                                                                  groupExpandedLeftIcon="triangleUp"

                                                                                  groupCollapsedLeftIcon="triangleDown"

                                                                                  topGroupExpandedRightIcon="chevronUp"

                                                                                  topGroupCollapsedRightIcon="chevronDown"

                                                                                  itemLeftIcon="disc"

                                                                                  itemChangeListener="#{panelMenuBean.updateCurrent}"

                                                                                  binding="#{panelMenuBean.panelMenu}" />

                                                                     

                                                              </h:form>

                                   

                                   

                                   

                                  [my backing bean]

                                   

                                  /*initialize every request time*/

                                   

                                  @PostConstruct

                                      public void initialize() {

                                          super.getLogger().info("PostConstruct - initialize() [request scope]");

                                         

                                          try {

                                                 ...

                                             

                                             List<FunzioneType> ff = funzz.getFunzione();

                                             

                                              for(FunzioneType f: ff) {

                                   

                                                  //per ogni primo livello recuperare separatamente i figli

                                                  UIPanelMenuGroup gruppo = addChildrenToMenuGroup(f);

                                                  gruppi.add(gruppo);

                                              }

                                   

                                              panelMenu = (UIPanelMenu)_getApplicationRef().createComponent(_getFacesCtx(),UIPanelMenu.COMPONENT_TYPE,"org.richfaces.PanelMenuRenderer");

                                              panelMenu.getChildren().addAll(gruppi);

                                             

                                          }catch(Throwable t) {

                                              super.getLogger().error("Eccezione: "+t.getMessage(),t);

                                          }

                                      }

                                   

                                  /*ItemChangeEvent from PanelMenu component */

                                  public void updateCurrent(ItemChangeEvent  event) {

                                          super.getLogger().debug("UUUUUU updateCurrent "+event.getNewItem().getId());

                                         

                                          //catch selected menu item

                                          selectedMenuItem = event.getNewItem().getId();       

                                      }

                                     

                                  /*ActionEvent from PanelMenuItem component */   

                                      public String actionCurrent(ActionEvent  event) {

                                          super.getLogger().debug("AAAAA actionCurrent "+event.getComponent().getId());

                                          super.getLogger().debug("AAAAA selectedMenuItem "+selectedMenuItem);

                                         

                                          //TODO

                                         

                                          return "base.example1";

                                      }

                                   

                                  /*method fro buildin an object to set children to PanelMenu (ignore this, focus only about bolder code please)*/

                                  private UIPanelMenuGroup addChildrenToMenuGroup(FunzioneType f) throws Throwable {

                                          super.getLogger().info("addChildrenToMenuGroup ["+

                                                          f.getCodice()+"@"+f.getNome()+" - "+BM_PROFILO+"]");

                                         

                                          UIPanelMenuGroup pmg = (UIPanelMenuGroup)_getApplicationRef().createComponent(

                                                  _getFacesCtx(),UIPanelMenuGroup.COMPONENT_TYPE,"org.richfaces.PanelMenuGroupRenderer");

                                         

                                          pmg.setLabel(f.getNome());

                                          pmg.setId(f.getCodice());

                                          //super.getLogger().debug("[Gruppo Menu Item] "+pmg.getLabel()+ "(codice funzione "+pmg.getId()+")");

                                         

                                          //recupero eventuali figli

                                            .....

                                         

                                          List<FunzioneType> ff = funzz.getFunzione();

                                         

                                         

                                          //figli del menuItemGroup pmg chiamante

                                          List<UIPanelMenuItem> figli = new ArrayList<UIPanelMenuItem>();

                                          for(FunzioneType fc: ff) {           

                                             

                                             

                                              //recupero eventuali figli di menuItem

                                              UIPanelMenuGroup gruppoFiglio = addChildrenToMenuGroup(fc);

                                              if(gruppoFiglio.getChildCount() > 0) {

                                                  //super.getLogger().debug("Figli presenti");

                                                  pmg.getChildren().add(gruppoFiglio);

                                              }

                                              else {

                                                  //add child to group

                                                 UIPanelMenuItem menuItem = (UIPanelMenuItem)_getApplicationRef().createComponent(

                                                          _getFacesCtx(),UIPanelMenuItem.COMPONENT_TYPE,"org.richfaces.PanelMenuItemRenderer");

                                                 

                                                  menuItem.setLabel(fc.getNome());

                                                  menuItem.setId(fc.getCodice());

                                                 

                                                 

                                                  MethodExpression actionExpr = _getApplicationRef().getExpressionFactory()

                                                              .createMethodExpression(_getFacesCtx().getELContext(),

                                                                      "#{panelMenuBean.actionCurrent}",

                                                                      Void.class,

                                                                      new Class[] { ActionEvent.class });

                                   

                                                  menuItem.addActionListener(new MethodExpressionActionListener(actionExpr));

                                                

                                                 

                                                  menuItem.setMode(PanelMenuMode.ajax);

                                                 

                                                  pmg.getChildren().add(menuItem);

                                                

                                              }

                                          }

                                         

                                          pmg.getChildren().addAll(figli);

                                         

                                          return pmg;

                                      }

                                   

                                   

                                   

                                  I set only actionListener and mode for each menu item that will compose the menu tree structure, and it works !

                                  But there is a problem that i can't understand, action will fire but it doesn't navigate from a page to another as i coded into actionCurrent method of actionListener menuIten setting,

                                  have i confused something ?

                                  thanks in advance

                                  • 14. Re: Panelmenuitem actions in binding bean not responding
                                    Matteo Mancini Newbie

                                    Ops ok, problem solved !!

                                    i can say that my example works fine and form is submitted successfully so my application can navigate through navigation-rules set,

                                    if anyone is interested i can post my example...

                                    1 2 Previous Next