13 Replies Latest reply on Mar 1, 2007 1:18 PM by Pete Muir

    selectOneMenu and commandButton conflict

    paata lominadze Master

      seam version : 1.1.6 GA
      i have login page and i want use identity class for jaas. also into login page i have selectOneMenu component for languages which is filled from database,
      when i cklick on login button nothing happend(did not call autenticator.autenticate method),
      if i remove filling of the selectOneMenu component all works fine :(
      can anybody help me ?

      1. components.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <components
       xmlns="http://jboss.com/products/seam/components"
       xmlns:core="http://jboss.com/products/seam/core"
       xmlns:drools="http://jboss.com/products/seam/drools"
       xmlns:security="http://jboss.com/products/seam/security"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:framework="http://jboss.com/products/seam/framework"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-1.1.xsd
       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-1.1.xsd
       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-1.1.xsd
      http://jboss.com/products/seam/components http://jboss.com/products/seam/components-1.1.xsd"
      >
       <framework:entity-query name="languages" ejbql="select l from Language l" />
       <framework:entity-query name="applications" ejbql="select a from Application a" />
      
       <core:init debug="true" jndi-pattern="@jndiPattern@"/>
      
       <core:manager concurrent-request-timeout="500"
       conversation-timeout="120000"
       conversation-id-parameter="cid"
       conversation-is-long-running-parameter="clr"/>
      
       <core:pages no-conversation-view-id="/home.xhtml"/>
      
       <core:managed-persistence-context name="entityManager"
       persistence-unit-jndi-name="java:/MagtiBillingEntityManagerFactory"/>
      
       <core:ejb installed="@embeddedEjb@"/>
      
       <drools:rule-base name="securityRules">
       <drools:rule-files>
       <value>/security.drl</value>
       </drools:rule-files>
       </drools:rule-base>
      
       <security:identity authenticate-method="#{authenticator.authenticate}"/>
      
       <event type="org.jboss.seam.notLoggedIn">
       <action expression="#{redirect.captureCurrentView}"/>
       </event>
       <event type="org.jboss.seam.postAuthenticate">
       <action expression="#{redirect.returnToCapturedView}"/>
       </event>
       <!-- For use with jBPM pageflow or process management -->
       <!--
       <core:jbpm>
       <core:process-definitions></core:process-definitions>
       <core:pageflow-definitions></core:pageflow-definitions>
       </core:jbpm>
       -->
      
      </components>
      


      2.login page
      <h:form>
       <table width="400" cellpadding="5" cellspacing="0" style="border: 1px solid #9e2629">
       <tr>
       <td class="LogonText" colspan="2" align="center">Login to System</td>
       </tr>
       <tr>
       <td class="td_new">
       <table width="100%" cellpadding="5" cellspacing="0" border="0">
       <tr>
       <td class="td_new" rowspan="5"><h:graphicImage value="/images/login_pic.gif"/></td>
       <td class="td_new">UserName</td>
       <td class="td_new">
       <h:inputText styleClass="font_style" value="#{identity.username}"/>
       </td>
      
       </tr>
      
       <tr>
       <td class="td_new">Password</td>
       <td class="td_new">
       <h:inputSecret styleClass="font_style" value="#{identity.password}"/>
       </td>
      
       </tr>
      
       <tr>
       <td class="td_new">Application</td>
       <td class="td_new">
       <!--
       <h:selectOneMenu styleClass="font_style" value=""/>
       -->
       <h:selectOneMenu styleClass="font_style" value="#{application.name}" converter="#{converters.applicationConverter}">
       <s:selectItems value="#{applications.resultList}" var="application" label="#{application.name}"/>
       </h:selectOneMenu>
      
       </td>
      
       </tr>
      
       <tr>
       <td class="td_new">Language</td>
       <td class="td_new">
       <h:selectOneMenu styleClass="font_style" value=""/>
       <!--
       <h:selectOneMenu styleClass="font_style" value="#{language.name}" converter="#{converters.languageConverter}">
       <s:selectItems value="#{languages.resultList}" var="language" label="#{language.name}" />
       </h:selectOneMenu>
       -->
       </td>
      
       </tr>
       <tr>
       <td class="td_right" colspan="2">
       <h:commandButton id="LoginBtn"
       name="LoginBtn"
       class="Btn2"
       value="Login"
       onblur="return this.myonblur();"
       onfocus="return this.myonfocus();"
       onmouseout="return this.myonmouseout();"
       onmouseover="return this.myonmouseover();"
       action="#{identity.login}"
       />
       <script type="text/javascript"><!--
       sjwuic_assign_button('loginForm:LoginBtn', defaultButtonStrings, true, false, false);
       //--></script>
       </td>
       <!--actionListener="" -->
       </tr>
       </table>
       </td>
       </tr>
       <tr>
       <td class="td_new" colspan="2"></td>
       </tr>
       <tr>
       <td class="td_new" colspan="2"></td>
       </tr>
       </table>
       </h:form>
      


      when i commented both of the h:selectOneMenu component after login click the page redirected to another, and if i uncomment one of them button does not work.





        • 1. Re: selectOneMenu and commandButton conflict
          Pete Muir Master

          You've probably got errors occuring on the coversion, validation or update model phase. Put an h:messages component on the page to see.

          • 2. Re: selectOneMenu and commandButton conflict
            paata lominadze Master

             

            "petemuir" wrote:
            You've probably got errors occuring on the coversion, validation or update model phase. Put an h:messages component on the page to see.


            hi petemuir,
            u're right i put h:messages into login page and i got an error like this :
             . value could not be converted to the expected type
            

            i wrote my own converter as you told me
            @Transactional
             public Converter getApplicationConverter() {
             return new Converter() {
            
             @Transactional
             public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
             if (arg2 == null) {
             return null;
             }
             try {
             return ((EntityManager) Component.getInstance("entityManager")).find(Application.class, Integer.valueOf(arg2));
             } catch (NumberFormatException e) {
             throw new ConverterException("Cannot Find Selected Language", e);
             }
             }
            
             @Transactional
             public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
             if (arg2 instanceof Language) {
             Application application = (Application) arg2;
             return application.getName().toString();
             } else {
             return null;
             }
             }
            
             };
             }
            


            here is my entity bean :
            @Entity
            @Table(name = "APPLICATION",schema="BillAdmin")
            @Name("application")
            @Scope(ScopeType.SESSION)
            public class Application implements Serializable {
            
             @Id
             @Column(name = "APPLICATION_ID", nullable = false)
             private BigDecimal applicationId;
            
             @Column(name = "NAME")
             private String name;
            
             @Column(name = "CODE")
             private BigInteger code;
            
             @Column(name = "DESCRIPTION")
             private String description;
            
             @Column(name = "REMARK")
             private String remark;
            
             @Column(name = "REC_STATUS")
             private BigInteger recStatus;
            
             @Column(name = "USER_ID")
             private BigInteger userId;
            
             @Column(name = "REG_DATE")
             @Temporal(TemporalType.DATE)
             private Date regDate;
            
             @Column(name = "UPD_DATE")
             @Temporal(TemporalType.DATE)
             private Date updDate;
            
             @OneToMany(cascade = CascadeType.ALL, mappedBy = "applicationId")
             private Collection<ApplicationsConfig> applicationsConfigCollection;
            
             public Application() {
             }
            
             public Application(BigDecimal applicationId) {
             this.applicationId = applicationId;
             }
            
             public BigDecimal getApplicationId() {
             return this.applicationId;
             }
             public void setApplicationId(BigDecimal applicationId) {
             this.applicationId = applicationId;
             }
            
             public String getName() {
             return this.name;
             }
            
             public void setName(String name) {
             this.name = name;
             }
            
             public BigInteger getCode() {
             return this.code;
             }
             public void setCode(BigInteger code) {
             this.code = code;
             }
            
             public String getDescription() {
             return this.description;
             }
            
             public void setDescription(String description) {
             this.description = description;
             }
            
             public String getRemark() {
             return this.remark;
             }
            
             public void setRemark(String remark) {
             this.remark = remark;
             }
            
             public BigInteger getRecStatus() {
             return this.recStatus;
             }
            
             public void setRecStatus(BigInteger recStatus) {
             this.recStatus = recStatus;
             }
            
             public BigInteger getUserId() {
             return this.userId;
             }
             public void setUserId(BigInteger userId) {
             this.userId = userId;
             }
             public Date getRegDate() {
             return this.regDate;
             }
             public void setRegDate(Date regDate) {
             this.regDate = regDate;
             }
             public Date getUpdDate() {
             return this.updDate;
             }
             public void setUpdDate(Date updDate) {
             this.updDate = updDate;
             }
             public Collection<ApplicationsConfig> getApplicationsConfigCollection() {
             return this.applicationsConfigCollection;
             }
             public void setApplicationsConfigCollection(Collection<ApplicationsConfig> applicationsConfigCollection) {
             this.applicationsConfigCollection = applicationsConfigCollection;
             }
             @Override
             public int hashCode() {
             int hash = 0;
             hash += (this.applicationId != null ? this.applicationId.hashCode() : 0);
             return hash;
             }
             @Override
             public boolean equals(Object object) {
             if (!(object instanceof Application)) {
             return false;
             }
             Application other = (Application)object;
             if (this.applicationId != other.applicationId && (this.applicationId == null || !this.applicationId.equals(other.applicationId))) return false;
             return true;
             }
            
             @Override
             public String toString() {
             return "com.magti.seam.beans.billAdmin.Application[applicationId=" + applicationId + "]";
             }
            }
            


            can u tell me why i got this error ?



            • 3. Re: selectOneMenu and commandButton conflict
              paata lominadze Master

              i tryed to use another ways.

              here is fragment of my program :

              1. login page:

              <h:selectOneMenu styleClass="font_style" value="#{application.name}" converter="#{converters.applicationConverter}">
               <s:selectItems value="#{applications.resultList}" var="application" label="#{application.name}"/>
               </h:selectOneMenu>
              


              2. components.xml
               <framework:entity-query name="applications" ejbql="select a from Application a" />
               <framework:entity-home name="applicationHome" entity-class="com.magti.seam.beans.billAdmin.Application"/>
               <factory name="application" value="#{applicationHome.instance}" />
              


              3. My Converter :
              @Transactional
               public Converter getApplicationConverter() {
               return new Converter() {
              
               @Transactional
               public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) throws ConverterException {
               if (arg2 == null) {
               return null;
               }
               try {
               return ((EntityManager) Component.getInstance("entityManager")).find(Application.class, Long.valueOf(arg2));
               } catch (NumberFormatException e) {
               throw new ConverterException("Cannot Find Selected Language", e);
               }
               }
              
               @Transactional
               public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) throws ConverterException {
               if (arg2 instanceof Application) {
               Application application = (Application) arg2;
               return application.getApplicationId().toString();
               } else {
               return null;
               }
               }
              
               };
               }
              


              4. and entity bean i posted above, but i remove @Name annotation.

              but error still appears,

              /login.xhtml @37,153 value="#{application.name}": Exception setting property name of base with class com.magti.seam.beans.billAdmin.Application, Bean: com.magti.seam.beans.billAdmin.Application, property: name, argument type mismatch
              


              • 4. Re: selectOneMenu and commandButton conflict
                Pete Muir Master

                #{application.name} references a String, you are trying to set it with a Application object. Likewise for language. Read up on JSF converters and what they do. And take a look at the EntityConverter on the wiki as it does what you are trying to do for you...

                • 5. Re: selectOneMenu and commandButton conflict
                  paata lominadze Master

                   

                  "petemuir" wrote:
                  #{application.name} references a String, you are trying to set it with a Application object. Likewise for language. Read up on JSF converters and what they do. And take a look at the EntityConverter on the wiki as it does what you are trying to do for you...


                  hi again,
                  for background i read JSF converters,
                  then i go to wiki for SeamEntityConverter (http://wiki.jboss.org/wiki/Wiki.jsp?page=SeamEntityConverter)
                  i download zip file ant tryed to understand.

                  after all i deside to do my job.

                  1.i added xmlns:ec="http://jboss.com/products/seam/entityconverter/taglib" into my facelet. and change selectonemenu component tag like this :

                  <s:decorate>
                   <h:selectOneMenu styleClass="font_style" value="#{application.name}">
                   <s:selectItems value="#{applications.resultList}" var="name" label="#{application.name}"/>
                   <ec:convertEntity entityClass="com.magti.seam.beans.billAdmin.Application"/>
                   </h:selectOneMenu>
                   </s:decorate>
                  



                  2. i modifyed my component.xml file :

                  <framework:entity-query name="applications" ejbql="select a from Application a" />
                   <framework:entity-home name="applicationHome" entity-class="com.magti.seam.beans.billAdmin.Application"/>
                   <factory name="application" value="#{applicationHome.instance}" />
                  


                  3. i put entityconverter.jar file into my WEB-INF/lib.

                  but page did not load :

                  Value is no String (class=com.magti.seam.beans.billAdmin.Application, value=com.magti.seam.beans.billAdmin.Application[applicationId=4]) and component _id17:_id26with path: {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /login.xhtml][Class: javax.faces.component.html.HtmlForm,Id: _id17][Class: org.jboss.seam.ui.UIDecorate,Id: _id25][Class: javax.faces.component.html.HtmlSelectOneMenu,Id: _id26]} does not have a Converter
                  


                  is there any mistake i did ?




                  • 6. Re: selectOneMenu and commandButton conflict
                    paata lominadze Master

                    i can't resolve this problem yet,
                    anybody knows about it ?

                    • 7. Re: selectOneMenu and commandButton conflict
                      paata lominadze Master

                      i can't resolve this problem yet,
                      anybody knows about it ?

                      • 8. Re: selectOneMenu and commandButton conflict
                        Pete Muir Master

                        At the very least it should be this

                        <h:selectOneMenu styleClass="font_style" value="#{foo.application}">
                         <s:selectItems value="#{applications.resultList}" var="name" label="#{application.name}"/>
                         <ec:convertEntity />
                        </h:selectOneMenu>


                        • 9. Re: selectOneMenu and commandButton conflict
                          Pete Muir Master

                          Oops, no, this is better

                          <h:selectOneMenu styleClass="font_style" value="#{foo.application}">
                           <s:selectItems value="#{applications.resultList}" var="application" label="#{application.name}"/>
                           <ec:convertEntity />
                          </h:selectOneMenu>


                          • 10. Re: selectOneMenu and commandButton conflict
                            paata lominadze Master

                            sorry petemuir for my disturb :(

                            i tryed it for a week and could not resolve this problem,

                            i added ur jar file into build.xml file

                            <copy todir="${war.dir}/WEB-INF/lib">
                             <fileset dir="${lib.dir}">
                             <include name="ajax4jsf.jar" />
                             <include name="oscache*.jar" />
                             <include name="jsf-facelets.jar" />
                             <include name="jboss-seam-*.jar" />
                             <include name="entityconverter.jar" />
                             <exclude name="jboss-seam-gen.jar" />
                             </fileset>
                             </copy>
                            


                            for copping this jar into war file(WEB-INF/lib)


                            <h:selectOneMenu styleClass="font_style" value="#{foo.application}">


                            what did u mean in foo?sorry i can't understand :(








                            • 11. Re: selectOneMenu and commandButton conflict
                              Pete Muir Master

                               

                              <h:selectOneMenu styleClass="font_style" value="#{foo.application}">


                              Foo is the backing bean on which you wish to set the application property. It could be just #{application} - though I'm not sure how well this works on the whole.

                              • 12. Re: selectOneMenu and commandButton conflict
                                paata lominadze Master

                                 

                                "petemuir" wrote:
                                <h:selectOneMenu styleClass="font_style" value="#{foo.application}">


                                Foo is the backing bean on which you wish to set the application property. It could be just #{application} - though I'm not sure how well this works on the whole.



                                ok,
                                1. i had entityconverter.jar into my war file
                                2.my project component.xml file looks like :
                                <framework:entity-home name="applicationHome" entity-class="com.magticom.billing.businesslayer.entitybeans.billAdmin.Application" />
                                 <factory name="application" value="#{applicationHome.instance}" />
                                 <framework:entity-query name="applications" ejbql="select a from Application a" />
                                

                                "applicationHome" is baking bean for login page.
                                "application" is name of this baking bean instance.
                                "applications" is is entity query.

                                3. my login page looks like

                                <h:selectOneMenu styleClass="font_style" value="#{application}">
                                 <s:selectItems value="#{applications.resultList}" var="application" label="#{application.name}"/>
                                 <ec:convertEntity />
                                 </h:selectOneMenu>
                                


                                in "h:selectOneMenu" component "#{application}" is name of the baking bean,
                                in "s:selectItems" component "#{applications.resultList}" is the result of entity query
                                the var attribute point to the factory.
                                ant at list this is <ec:convertEntity /> is for converting entity.

                                but always i got the same error

                                Value is no String (class=com.magti.seam.beans.billAdmin.Application, value=com.magti.seam.beans.bil
                                lAdmin.Application[applicationId=4]) and component _id17:_id26with path: {Component-Path : [Class: j
                                avax.faces.component.UIViewRoot,ViewId: /login.xhtml][Class: javax.faces.component.html.HtmlForm,Id:
                                 _id17][Class: org.jboss.seam.ui.UIDecorate,Id: _id25][Class: javax.faces.component.html.HtmlSelectO
                                neMenu,Id: _id26]} does not have a Converter
                                


                                is another way to resolve this problem? without entity converter ?
                                or what i did wrong ?

                                oo and i put entityconverter.jar into jboss server lib folder. is it needed ?


                                • 13. Re: selectOneMenu and commandButton conflict
                                  Pete Muir Master

                                  No. Don't put it in the lib folder. Follow the examples provided for packaging.

                                  It looks like converter isn't getting used. As for why... You should check with a breakpoint whether the converter is used. You could also try registering the converter by id - org.jboss.seam.EntityConverter iirc.