4 Replies Latest reply on Mar 6, 2011 4:19 PM by geschtli

    Different calling conventions for bean methods??

    geschtli

      Hi

       

      I have a strange effect in my little test application.

       

      i have that little bean (CDI convention):

       

      @Named

      @SessionScoped

      public class LoginBean implements Serializable

      {

          private static final long serialVersionUID = 2989679125285684221L;

          private String alias = "";

          private String auth = "";

       

         @Inject private AccountManager am; 

       

          public String getAlias()

           {

             return alias;

           }

       

          public String getPassword()

           {

             return auth;

           }

       

          public void setAlias(final String _alias)

           {

              alias = _alias;

           }

       

          public void setPassword(final String _auth)

           {

              auth = _auth;

           }

       

          public String getLogin()

           {

            if ( am.login(alias, auth) )

             return "loginPass";   

            else

             return "loginFail";

           }

         }

       

      with Getter and Setter in it.

       

      Now the little calls then:

       

      <ui:composition 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">

       

       

             <h:form ajaxSubmit="true">  

                      <h:outputText value="#{msg.name}" />

                     <h:inputText value="#{loginBean.alias}" required="true" />

                     <h:outputText value="#{msg.pwd}" />

                     <h:inputSecret  value="#{loginBean.password}"  required="true" />

                     <a4j:commandButton value="GO" action="#{loginBean.getLogin}" render="name" />

                     <h:outputText id="name" value="  Name:#{loginBean.alias}" />

              </h:form>

      </ui:composition>

       

      Now, for the ajax-button here, i can't simple set #loginBean.login,

      similar to the other methods. No i must set the original method name,

      otherwise i got the following exception : 'javax.el.MethodNotFoundException'.

       

      Now my question. Is there something in richfaces, that collides with

      the calling convention for methods, if using 'CDI' in the application.

        • 1. Different calling conventions for bean methods??
          ilya40umov

          Your code looks strange for me because when I see get method it basically means that the bean has a such variable or at least pretending to have it. Why can't you just name your method "login" in your JSF bean?

          • 2. Different calling conventions for bean methods??
            geschtli

            If i use just a simple 'login',  the application hangs with a "javax.el.MethodNotFoundException".

            If i use <h:commandButton... instead <a4j:commandButton... i  must use only simple 'login' and it works.

            Does i use <a4j:commandButton... i must call 'getLogin', original mthod name, so that my

            application works correct.

            • 3. Different calling conventions for bean methods??
              ilya40umov

              In case of a4j:commandButton or h:commandButton you should use the full name of method because it's an action method. JSF uses property-like access to methods only when it's supposed to be a field of a bean. In case of an action method it should be the full name. And I suggest you to name the method inside the bean login but not getLogin. It's not a good approach when your getters start holding any bussiness logic(Some times they can contain some converting/valiudation/checks but not a call of bussiness methods).

              • 4. Different calling conventions for bean methods??
                geschtli

                Thanks Ilya,

                 

                Now i understand the problem. In an action method i must deliver the original full method name.

                That was my misunderstanding.