9 Replies Latest reply on Mar 15, 2007 5:06 PM by tizi

    passing values entered by user to a4j:jsFunction

    tizi

      Hi,

      I have a set of <h:inputtext> <h:selectonemenu> inside one <h:panelgrid>. Inside same <h:panelgrid> I am trying to call <a4j:jsFunction>. Is it possible to pass the values which user entered in <h:inputtext> or selected in <h:selectonemenu> to <a4j:jsfunction>?
      This is wat I am implying :

      <h:panelGrid columns="1" border="0" headerClass="sect_header" footerClass="sect_footer" styleClass="pr_bold">
       <h:panelGrid columns="2" columnClasses="quickCreateSecCol1">
       <h:outputLabel value="#{msg.isellForm_QuickCreat_Country}" style="width: 70px"/>
      
       <h:selectOneMenu id="selectCountry" value="#{backing_CustSearchBean.currentCountry}" >
       <f:selectItem itemValue="usa" itemLabel="USA"/>
       </h:selectOneMenu>
      
       <h:outputText value="#{msg.isellForm_QuickCreat_Fname}" style="width: 70px"/>
       <h:inputText value="#{backing_CustSearchBean.createFName}" />
       <h:outputText value="#{msg.isellForm_QuickCreat_Lname}" style="width: 70px" />
       <h:inputText value="#
      {backing_CustSearchBean.createLName}" />
      
      <h:outputLabel value="Save" styleClass="qBox" style="vertical-align: middle; cursor:pointer" onclick="saveData('#{backing_CustSearchBean.createFName}')"/>
      
      </h:panelgrid>
      <a4j:jsFunction name="saveData" action="#{backing_CustSearchBean.saveNewCustomer}" immediate="true" >
       <a4j:actionparam name="create_name" assignTo="#{backing_CustSearchBean.createFName}"></a4j:actionparam>
      </a4j:jsFunction>


      As it can be seen that I am trying to catch the values entered by user in actionparam. But this value is not available in my managed bean.

      How can I pass the values entered by user to jsFunction?

      Thanks in advance!!

        • 1. Re: passing values entered by user to a4j:jsFunction

          immediate="true" means bypassing the validation and model update phases. Ie. request data should not update the beans

          outputLabel onclick is formed on the server and has no relationship with inputText

          So, you are double guarantied that you will NOT have what you want.

          I suggest, you complicated the code too much. Most likely, if you remove h:outputLabel with a4j:jsFunction and replace them with just a4j:commandLink, you will have the #{backing_CustSearchBean.createFName} already updated when the action on the a4j:commandLink is invoked

          • 2. Re: passing values entered by user to a4j:jsFunction
            tizi

            Actually this again happens to be the case where for parent tags, rendered is false initially. So I am not getting the control going to action attribute (I had posted this day before yesterday and resolved it through jsFunction).

            Thats why I was trying to find the workaround through jSFunction. So if I use <h:outputtext> and remove immediate=true, will I be getting data in the managed bean? Or is there a specific way of declaring onclick="saveData()" where I can pass values entered by user.

            Thanks a lot for replying.

            • 3. Re: passing values entered by user to a4j:jsFunction
              tizi

              Can you please let me know how do i set the value of <h:inputhidden> in managed bean and catch it in jsp? If I can do that I'll go for normal div tags. but as of now I am not able to change the value of hidden field in managed bean...???

              • 4. Re: passing values entered by user to a4j:jsFunction

                I did not see the "hidden field" in the above code. Could you post the actual one that you have now

                • 5. Re: passing values entered by user to a4j:jsFunction
                  tizi

                  Here is the code:

                  <a4j:commandButton
                   id="commandButton3"
                   action="#{backing_CustSearchBean.serchCustomer}"
                  
                  
                   image="images/btn_search.gif"
                   style="position: relative; margin-right: 5px;"
                   actionListener="#{backing_CustSearchBean.checkText}"
                   immediate="true"
                   status="wait"
                   oncomplete="showQuickCreate()"
                   >
                   <h:inputHidden id="jsfHidden" value="#{backing_CustSearchBean.jsfHidden}" />
                  
                   <a4j:status id="wait">
                   <f:facet name="start" >
                   <h:graphicImage url="images/SpinGear2.gif" style="position: absolute; left: 378px; top: 216px; width: 19px; height: 18px;"/>
                   </f:facet>
                   </a4j:status>
                  
                   </a4j:commandButton>



                  inside managed bean serchCustomer action I do this:
                  jsfHidden.setValue("failure");

                  But I am not able to catch this value in the showQuickCreate javascript function ...


                  • 6. Re: passing values entered by user to a4j:jsFunction

                    I still did not see the whole picture what do you have on your side. The latest code snippet has no jsFunction

                    • 7. Re: passing values entered by user to a4j:jsFunction
                      tizi

                      This time I am using simple javascript function as shown below:

                      <script type="text/javascript">
                      function showQuickCreate(){
                      
                      alert('value in the hidden object --->'+document.getElementById('jsfHidden').value );
                      }
                       </script>


                      I dont catch the value here.

                      • 8. Re: passing values entered by user to a4j:jsFunction

                        You just reference to a wrong id there.

                        If you have:

                        <h:form id="myform">
                         <h:inputHidden id="jsfHidden" ..../>
                        </h:form>


                        you have to use:

                        document.getElementById('myform:jsfHidden').value




                        • 9. Re: passing values entered by user to a4j:jsFunction
                          tizi

                          Hi can you please also suggest how should set it (the hidden value) in managed also?

                          I tried
                          1)HTMLHiddenInput , jsfHidden.setValue('failure')
                          2) private String jsfhidden , jsfHiddden = "failure"
                          3)session.setAttribute("jsfHidden","failure") and in jsf
                          <h:inputHidden id="jsfHidden" value="#{sessionScope.jsfHidden}" />

                          But with non of above my recent value of "jsfHidden" is shown in alert.
                          i.e.
                          alert( document.getElementById('myform:jsfHidden').value)