2 Replies Latest reply on Oct 24, 2007 6:34 AM by dsleeper

    Dynamically setting HtmlMenuItem.setActionListener problem

    dsleeper Newbie

      I am currently building a small webshop like menu with category listing using a combination of the toolBar, dropDownMenu and menuItem components.The menu needs to be created dynamically by fetching a list of categories from a DAO in the background.

      If a user clicks one of the menuItems in the toolBar an actionListener event should be triggered and thereby a redirect to the proper category listing view.

      For now I've added all the menuItems with this method:

      private HtmlMenuItem createOneMenuItem(Category c)
       {
       HtmlMenuItem menuItem = new HtmlMenuItem();
       menuItem.setId("_" + String.valueOf(c.getId()));
       menuItem.setValue(c.getName());
       menuItem.setAjaxSingle(true);
       //menuItem.setAction(action)
       menuItem.setActionListener(FacesContext.getCurrentInstance().getApplication().createMethodBinding(
       "#{ShopMenu.processMenuClickedAction}", new Class[0]));
      
       return menuItem;
       }


      My problem now is that:
      1. "#{ShopMenu.processMenuClickedAction}" works just fine if I reference it from the JSP file, but when I click a menuItem that has been added dynamically this exception is thrown:
      java.lang.NoSuchMethodException: com.lq.web.shop.ShopMenu.processMenuClickedAction()
       java.lang.Class.getMethod(Unknown Source)
       org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:121)
       javax.faces.component.UICommand.broadcast(UICommand.java:89)
       org.ajax4jsf.component.AjaxActionComponent.broadcast(AjaxActionComponent.java:61)
       org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:184)
       org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:162)
       org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:350)
       org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
       org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
       org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
       org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:141)
       org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       com.lq.data.hibernate.HibernateFilter.doFilter(HibernateFilter.java:47)
       org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)


      2. I've searched this forum and found one way of referencing a methodBinding to an actionListener:
      FacesContext fc = FacesContext.getCurrentInstance();
      ELContext el = fc.getELContext();
       MethodExpression me = fc.getApplication().getExpressionFactory().createMethodExpression(el, "#{testPage.testMeth}", null, new Class[0]);


      But none of the above code works for me as my developer IDE says:
      the method getELContext is undefined for the type FacesContext
      the method "fc.getApplication().getExpressionFactory()" is undefined for the type Application

      Perhaps I'm missing some jars in my classpath here? I'm using Myfaces and Richfaces together (I'm not using SEAM)

      Is there any other way to create a methodbinding to use in a menuItem?

      Any suggestions on other way of doing the menu click/redirect function as mentioned in the beginning of this post?