4 Replies Latest reply on Jul 11, 2007 11:01 PM by dantevaze

    Problem with menu onchange action

    dantevaze

      Hello Everyone.

      I am working on a JSF application,with Facelets,Tomahawk and Ajax4jsf. Im having trouble with the h:selectOneMenu. In my xhtml file, I have two selectOneMenu elements,and one h:inputText element. All the three of them contribute to display a name,in another h:inputText. The two selectOneMenu are not working,but the inputText is. In the resulting inputText,where the combination of the three must appear,only the changes in the last inputText are viewed.
      Here is the code:

      <ui:define name="body">
       <a4j:region selfRendered="true">
       <h:form>
       <h:outputText value="#{msg.projectType}"/>
       <h:selectOneMenu value="#{tcprojBean.projectType}">
       <f:selectItems value="#{tcprojBean.projtypes}"/>
       <a4j:support event="onchange" action="#{tcprojBean.methodBind}" ajaxSingle="true"reRender="repeater"/>
       </h:selectOneMenu>
      
       <h:outputText value="#{msg.customerName}"/>
       <h:selectOneMenu value="#{tcprojBean.customer}">
       <f:selectItems value="#{tcprojBean.customers}"/>
       <a4j:support event="onchange" action="#{tcprojBean.methodBind}" ajaxSingle="true" reRender="repeater" />
       </h:selectOneMenu>
       <h:outputText value="#{msg.projectName}"/>
       <h:inputText value="#{tcprojBean.iname}">
       <a4j:support event="onkeyup" ajaxSingle="true" reRender="repeater" />
       </h:inputText>
       <h:outputText value="#{msg.projectFName}"/>
       <h:inputText id="repeater" disabled="true" value="#{tcprojBean.trigram} #{tcprojBean.type} #{tcprojBean.iname}"/>
      
       <h:commandButton action="#{tcprojBean.createTcProject}" value="#{msg.createProject}" title="Submit"></h:commandButton>
       </h:panelGrid>
       </h:form>
       </a4j:region>
       </ui:define>
      


      And the backing bean method is defined as:

      public void methodBind(){
      System.out.println("test");
      //this.type = "-"+ptype[this.getProjectType()]+"-";
      //this.trigram = this.getCustomer().getTrigram();
      }

      just to test if the method is fired with the event. The bean is defined in the faces-config.xml with a session scope. Just to try, i put in another page an
      h:SelectOneMenu element alone with a h:inputText,and there it works. I even put a System.out inside the Backing Bean "projecType" property setter,and that is working too. I can´t tell why this is not working. I´d thank you lots for your help.


        • 1. Re: Problem with menu onchange action

          try to put each selectOneMenu into the own a4j:region

          • 2. Re: Problem with menu onchange action
            dantevaze

            I tried,creating an ajax region for each element that triggers an update (1st selectOneMenu,2nd selectOneMenu,and an inputText). It looks like this:

            <ui:define name="body">
            
             <h:form>
             <br/>
             <h:outputText value="#{msg.projectType}"/>
             <a4j:region selfRendered="true">
             <h:selectOneMenu value="#{tcprojBean.projectType}">
             <f:selectItems value="#{tcprojBean.projtypes}"/>
             <a4j:support event="onchange" action="#{tcprojBean.methodBind}" ajaxSingle="true" reRender="repeater"/>
             </h:selectOneMenu>
             </a4j:region>
            
             <h:outputText value="#{msg.customerName}"/>
             <a4j:region>
             <a4j:status startStyle="font-color:red" stopText="Ready" startText="Request under process"/><br/>
             <h:selectOneMenu value="#{tcprojBean.customer}">
             <f:selectItems value="#{tcprojBean.customers}"/>
             <a4j:support event="onchange" action="#{tcprojBean.methodBind}" ajaxSingle="true" reRender="repeater" />
             </h:selectOneMenu>
             </a4j:region>
             <h:outputText value="#{msg.projectName}"/>
             <a4j:region selfRendered="true">
             <h:inputText value="#{tcprojBean.iname}">
             <a4j:support event="onkeyup" ajaxSingle="true" reRender="repeater"/>
             </h:inputText>
             </a4j:region>
             <h:outputText value="#{msg.projectFName}"/>
             <a4j:region selfRendered="true">
             <h:inputText id="repeater" disabled="true" value="#{tcprojBean.trigram}#{tcprojBean.type}#{tcprojBean.iname}"/>
             </a4j:region>
            
             <br/>
             <h:commandButton action="#{tcprojBean.createTcProject}" value="#{msg.createProject}" title="Submit"></h:commandButton>
             </h:panelGrid>
             </h:form>
             </ui:define>
            



            Now the first component(the SelectOneMenu that fires the methodBind method) and the first inputText work fine, updating the inputText marked with id "repeater". I added the a4j:status tag to check if its triggering,and it does the trigger,but it doesn´t find the method binded or dont know what happens.
            Could you give me some advice? Thank you

            • 3. Re: Problem with menu onchange action

              use a4j:log to monitor the ajax traffic during the development.

              I did no see you control the error messages for this form. Add somewhere:

              <a4j:outputPanel ajaxRendered="true">
               <h:messages />
              </a4j:outputPanel>


              you have:
              <a4j:region selfRendered="true">
               <h:inputText id="repeater" disabled="true"
               value="#{tcprojBean.trigram}#{tcprojBean.type}#{tcprojBean.iname}"/>
              </a4j:region>

              a) Using region here is useless because you never submit this value by ajax
              b) in general, h:inputText does not presume to something that you have as a value for "value" (it might not be a problem while you have disabled="true") there.



              BTW, do you know why you use "seffRendered="true" for regions?


              • 4. Re: Problem with menu onchange action
                dantevaze

                Thanks a lot for your help. I saw that the problem was the data model, but I didnt see it before because the errors didn´t interrupted the application or threw any exceptions. BTW,i don´t know what the selfRendered attribute is for,I just saw it on a tutorial. Im a newby at this..but thanks a lot. By the way...do you know how to disable or activate a component (like an inputText,or even a tomahawk inputCalendar?),depending on the user selection of a menu or radio button? This because I need to search depending on the user criteria, like a date,or maybe a name,or maybe options from a menu, but I want to enable or activate the component indicated for that criteria, like, for example, activate the calendar when the user selects to search by date,disabling the inputText element. Any ideas?

                Thanks.
                Dan