2 Replies Latest reply on Mar 22, 2011 6:36 PM by nbelaevski

    rich:menuItem "action" and "actionListener" attributes not evaluating MethodExpression correctly when passed by ui:param

    ultrapod

      Hi - I'm running into a similar issue to one I recently posted in this forum (Forum link, JIRA) about a specific control attribute that was supposed to accept a MethodExpression but was improperly evaluating it as a ValueExpression instead when passed a MethodExpression by a ui:param.  The problem I am having now is in the rich:menuItem control, with both the "action" and the "actionListener" attributes.  When I directly reference a backing bean action or actionListener method, the backing method gets called properly, but when I pass a method via a ui:param I get a bogus PropertyNotFoundException.

       

      Here is my test case:

       

      TestMenuBean.java

       

      @ManagedBean(name="TestMenuBean")
      @SessionScoped
      public class TestMenuBean
      {
          private static Logger logger = Logger.getLogger(TestMenuBean.class.getName());
      
          public String action()
          {
              logger.info("action");
      
              return null;
          }
      
          public void actionListener(ActionEvent event)
          {
              logger.info("actionListener");
          }
      
      }
      

       

       

      test.xhtml

       

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html" 
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">
      
          <ui:composition>
              <h:head>
              </h:head>
      
              <h:body>
                  <h:form> 
                      <rich:toolbar>
      
                          <rich:dropDownMenu label="Test">
      
                              <ui:include src="/test_menu_item_server.xhtml">
                                  <ui:param name="menu_action" value="#{TestMenuBean.action}"/>
                                  <ui:param name="menu_label" value="Indirect Action"/>
                              </ui:include>
      
                              <rich:menuSeparator />
      
                              <rich:menuItem submitMode="server"
                                              action="#{TestMenuBean.action}" 
                                              label="Direct Action"/>
      
                              <rich:menuSeparator />
      
                              <ui:include src="/test_menu_item_ajax.xhtml">
                                  <ui:param name="menu_action_listener" value="#{TestMenuBean.actionListener}"/>
                                  <ui:param name="menu_label" value="Indirect Action Listener"/>
                              </ui:include>
      
                              <rich:menuSeparator />
      
                              <rich:menuItem submitMode="ajax"
                                              actionListener="#{TestMenuBean.actionListener}" 
                                              label="Direct Action Listener"/>
      
                          </rich:dropDownMenu>
                      </rich:toolbar>
                  </h:form>
              </h:body>
          </ui:composition>
      
      </html>
      

       

       

      test_menu_item_ajax.xhtml

       

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html" 
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">
      
          <ui:composition>
              <rich:menuItem submitMode="ajax"
                              actionListener="#{menu_action_listener}" 
                              label="#{menu_label}"/>    
          </ui:composition>
      </html>
      

       

       

      test_menu_item_server.xhtml

       

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html" 
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">
      
          <ui:composition>
              <rich:menuItem submitMode="server"
                              action="#{menu_action}" 
                              label="#{menu_label}"/>    
          </ui:composition>
      </html>
      

       

       

      Clicking on the "Direct Action" and "Direct Action Listener" menu items results in the backing bean action methods being called properly, as would be expected.

       

      Clicking on the "Indirect Action" and "Indirect Action Listener" results in an exception:

       

      javax.el.PropertyNotFoundException: /test_menu_item_server.xhtml @13,30 action="#{menu_action}": /test.xhtml @21,69 value="#{TestMenuBean.action}": The class 'foo.TestMenuBean' does not have the property 'action'.

       

      As before, it seems to me that this is a nearly identical issue to the one I already observed in the a4j:ajax "listener" attribute.  In any case, it seems to me that the rich:menuItem control is incorrectly evaluating the ui:param as a ValueExpression rather than a MethodExpression.  Since it resembles the previous bug so strongly, I'm going to go ahead and open up a JIRA issue on this right away.  I'll link to it here once I've opened it.  If I'm wrong in opening up an issue, I'll be happy to take my medicine!