5 Replies Latest reply on May 30, 2008 4:15 AM by Daniel Soneira

    submit only some fields

    Leo - Newbie

      hello!
      I am working with richfaces 3.2.0.GA.

      I have one page with one form. The form has several fields to store in my bean when I click the mainButton. But inside the form there are one specificField that I use to build with ajax a dynamicList, so when I click in in a ajaxLink then I put a new item in the dynamicList.

      Here is my code:


      <a4j:form id="myForm">
      .....................
      .... form fields ....
      .....................
      
       <h:inputText id="specificField" value="#{myBean.specificField}" />
      
      
       <a4j:commandLink id="ajaxLink"
       action="#{myBean.addItem}"
       reRender="dynamicList">
       <s:conversationId />
       </a4j:commandLink>
      
       <a4j:outputPanel id="myOutputPanel" ajaxRendered="true" >
       <rich:orderingList id="dynamicList" value="#{myBean.list}" var="r">
       <rich:column>
       <f:facet name="header">
       <h:outputText value="HEADER"/>
       </f:facet>
       <h:outputText value="#{r.property}"/>
       </rich:column>
       </rich:orderingList>
       </a4j:outputPanel>
      
      ..........................
      .... more form fields ....
      ..................... .....
       <a4j:commandButton id="mainButton"
       action="#{myBean.saveMyForm}">
       <s:conversationId/>
       </a4j:commandButton>
      </a4j:form>
      



      The problem is that validation errors of other fields (except specificField ) cause not to rerender the list correctly. If no validation errors the list rerenders fine. So I have two question for you?


      1. Is posible to submit only a few values with a4j:commandLink, or similar component?
      2. If not, is possible to force rerender of dynamicList even if fails validation of other fields?



      Thanks in Advance


        • 2. Re: submit only some fields
          Leo - Newbie

          Thanks for your help, Sergey

          I have just read about ajaxSingle=true. I read that using it only current component will be submited. So if I put in commandLink the value of specificField wont be submited, is this true?
          Can I use actionparam to send this value to server in this way?:

          <a4j:commandLink id="ajaxLink"
           ajaxSingle="true"
           action="#{myBean.addItem}"
           reRender="dynamicList">
           <a4j:actionparam name="n" value="#{myBean.specificField}" />
           <s:conversationId />
          </a4j:commandLink>



          I was thinking in use a nested form with only this field inside. Is this possible?

          P.S. Sorry for the cross post. I mixed up putting in this forum, I thought the right one was Richfaces. My apoligies.


          • 3. Re: submit only some fields
            Sergey Smirnov Master

            Hmm? Where did you read that?


            ajaxSingle - boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only.

            1) the whole form is submitted
            2) only component marked with ajaxSingle="true" is processed.

            The result - the validation rules on other components are invoked, because their are not processed, but not because of their are not submitted.

            Sure, you can use a4j:actionParam as well as f:param to pass some data together with commandLink. However, you also can point to some of the form components if you want to add them to the processing.

            Like that:

            <%-- will be excluded --%>
            <h:inputText id="blahblah" required="true" ...... />
            
            <%-- will be included --%>
            <h:inputText id="foo" ...... />
            ...
            <%-- will be included --%>
            <h:inputText id="bar" ...... />
            
            <a4j:commandLink id="ajaxLink"
             ajaxSingle="true"
             process="foo, bar"
             ........
            </a4j:commandLink>



            • 4. Re: submit only some fields
              Leo - Newbie

              Thanks Sergey, I confused myself with ajaxSingle=true ;)
              now I understand a bit more of AJAX
              Your solution works perfect for me.
              I am using process to update values that I need.

              Another alternative that worked for me is to nest other a4j:form and surround this last with a4j:region. In this form I put only the fields I need in my ajax request.

              <a4j:form id="mainForm">
              .....
               <%-- will be excluded --%>
               <h:inputText id="blahblah" required="true" ...... />
              .....
               <4j:region id="myRegion">
               <4j:form id="ajaxForm">
              
              
               <%-- will be included --%>
               <h:inputText id="foo" ...... />
               ...
               <%-- will be included --%>
               <h:inputText id="bar" ...... />
              
               <a4j:commandLink id="ajaxLink"
               ajaxSingle="true"
               process="foo, bar"
               ........
               </a4j:commandLink>
              
               </a4j:form>
               </a4j:region>
               ....
              </a4j:form>
              


              Could be any problem with this?


              • 5. Re: submit only some fields
                Daniel Soneira Novice

                Nesting forms is a BAD idea indeed :) Never do that.

                You can have multiple forms on one page - but DON'T nest them.