1 Reply Latest reply on Mar 29, 2008 2:55 PM by pmuir

    Input fields lose value in table using immediate=true

      My understanding is that this is a limitation of JSF, but since Seam fixes so many JSF limitations, I am hoping Seam has an answer for this also.


      I have a web page where the user can add new items to a list and edit values of existing items in the list.  This is implemented in a facelets view as follows:



      <a:outputPanel id="questionPanel">
         <h:dataTable value="#{questionnaire.questions}" var="question">                       
            <h:column>
               <f:facet name="header">Question Text</f:facet>
                  <h:inputText id="description" value="#{question.description}" required="true"/>
            </h:column>             
            <h:column>
               <a:commandLink value="delete" reRender="questionPanel" action="#{questionnaire.removeQuestion(question)}" immediate=true" />
            </h:column>
         </h:dataTable>
      </a:outputPanel>
      
      <a:commandButton value="add a question" reRender="questionPanel" action="#{questionnaireController.removeQuestion(question)}" immediate=true" />
      
      <h:commandButton value="save" action="#{questionnaireController.save}"/>



      I have specified immediate="true" on the ajax commands because the user should be able to add to the list without being stopped by incomplete fields elsewhere on the page.  However, this causes an issue in that the values entered into input fields in the table are lost when the user clicks add or delete. I can confirm this issue only applies to the fields in the table as I have a couple of input fields outside of the table which are retained when the page is rendered.  BTW, the behaviour is the same when using ui:repeat instead of h:dataTable.


      The behaviour with bypassUpdates="true" on the ajax commands is better, but results in error messages showing for the incomplete fields as the user adds or deletes items.  I'd prefer this validation to just kick in when the user hits save.


      So, any neat solutions out there? the immediate="true" seems intuitively correct (i.e. don't bind inputs to model until save), but I need it to work inside the table.  The discussion I linked to at the start of this post talks about subforms which appears to be part of the adf faces library.  Perhaps seam or richfaces provides something similar?


      Thanks in advance.
      Willy.

        • 1. Re: Input fields lose value in table using immediate=true
          pmuir

          Your analysis is correct, but really immediate="true" is a hack in JSF and shouldn't be used.


          Sub forms is one way to do it (Seam and RF don't have anything similar) AFAIK, otherwise I think you can use a <a:region /> - but someone like Damian probably knows more (or ask on the RichFaces forum).