1 2 Previous Next 24 Replies Latest reply on Jun 19, 2014 5:24 AM by Marcel Kolsteren

    Validation and refresh problems...

    Casey Boyd Novice

      I have 2 forms on a page...

      The top form is a table with a list of records. I use the onclick method to select a record in the table.

      The bottom form is a group of tabs showing information about the selected record.

      Example:

      A table with each row being a user. Tabs at the bottom are Address (which shows address information), Client (Showing all clients the User is in charge of), and so on. When you click bob, the tabs show all of bob's information. When you click on Amy, it shows all of Amy's information in the tabs...

      This works great...

      The problem is when I try to update the fields in the tabs with validation.

      If I have a multiple input boxes with the <s:validate/> tag and required=true and try to submit the bottom form, the only fields that update when a click on a new row in the top form are the fields that failed the validation.

      The backing bean is correct. But once the validation fails, the fields that do validate do not get refreshed afterwards.

      Basically if a form fails to submit because of validation, input boxes in the rich:tab do not update during any action afterwards...

      Let me know if you need to see code...

      Thanks

      Indy

        • 1. Re: Validation and refresh problems...
          Ilya Shaikovsky Master

          Yes it's a good idea to have some code snippets to be pasted from here and checked.

          • 2. Re: Validation and refresh problems...
            Casey Boyd Novice

             

            
            <h:form id="frmUsers">
            
            
             <rich:dataTable id="tblUsers" var="varUser" value="#{usermanager.users}">
            
             <a4j:support event="onRowClick" action="#{usermanager.selectUser(varUser)}" reRender="tplUserInfo, tblUsers" />
            
             <f:facet name="header">
            
             <rich:columnGroup>
            
             <rich:column>
             <h:outputText value="Username" />
             </rich:column>
            
             <rich:column>
             <h:outputText value="First Name" />
             </rich:column>
            
             <rich:column>
             <h:outputText value="Last Name" />
             </rich:column>
            
            
             </rich:columnGroup>
            
             </f:facet>
            
             <rich:column><h:outputText value="#{varUser.username}" /></rich:column>
             <rich:column><h:outputText value="#{varUser.firstname}" /></rich:column>
             <rich:column><h:outputText value="#{varUser.lastname}" /></rich:column>
            
             </rich:dataTable>
            
             <rich:spacer height="8" />
            
             <rich:datascroller id="dslUsers" for="tblUsers" maxPages="50" rendered="#{users.rowCount > 0}"/>
            
            </h:form>
            
            
            <h:form id="frmUserInfo">
            
             <a4j:commandButton value="Update" action="#{usermanager.updateUser}" reRender="tblUsers, tplUserInfo" ></a4j:commandButton>
            
             <rich:tabPanel id="tplUserInfo" switchType="client">
            
             <rich:tab label="Personal Information">
            
             <h:panelGrid columns="2">
            
             <h:outputText value="First Name:" />
             <s:decorate>
             <h:inputText value="#{usermanager.selectedUser.firstname}">
             <s:validate/>
             </h:inputText>
             </s:decorate>
            
             <h:outputText value="Middle Name:" />
             <s:decorate>
             <h:inputText value="#{usermanager.selectedUser.middlename}">
             <s:validate/>
             </h:inputText>
             </s:decorate>
            
             <h:outputText value="Last Name:" />
             <s:decorate>
             <h:inputText value="#{usermanager.selectedUser.lastname}">
             <s:validate/>
             </h:inputText>
             </s:decorate>
            
             </h:panelGrid>
            
             </rich:tab>
            
             </rich:tabPanel>
            
            </h:form>
            
            


            The method selectUser takes the user object in the table and populates the tabs below. (selectedUser).

            The onComplete rerenders the tabPanel to show the new information each time you click a new record.

            All this works great.

            The problem occurs when you clear the values for middle and last name, BUT keep first name with a value.

            You hit the update button and the validation catches the errors (required=true) and error is displayed.

            Now, click on a new record, the First Name field now stays the same no matter what record you click on, but the last and middle name keep changing...



            • 3. Re: Validation and refresh problems...
              Casey Boyd Novice

              no edit button, sorry...

              There is a required="true" on the fields within the tabpanel

              • 4. Re: Validation and refresh problems...
                Casey Boyd Novice

                Ok...more info...

                If you add some <h:outputText> rendering the exact same attribute on the bean, it works fine but the <h:inputText> does not

                
                <h:form id="frmUsers">
                
                
                 <rich:dataTable id="tblUsers" var="varUser" value="#{usermanager.users}">
                
                 <a4j:support event="onRowClick" action="#{usermanager.selectUser(varUser)}" reRender="tplUserInfo, tblUsers" />
                
                 <f:facet name="header">
                
                 <rich:columnGroup>
                
                 <rich:column>
                 <h:outputText value="Username" />
                 </rich:column>
                
                 <rich:column>
                 <h:outputText value="First Name" />
                 </rich:column>
                
                 <rich:column>
                 <h:outputText value="Last Name" />
                 </rich:column>
                
                
                 </rich:columnGroup>
                
                 </f:facet>
                
                 <rich:column><h:outputText value="#{varUser.username}" /></rich:column>
                 <rich:column><h:outputText value="#{varUser.firstname}" /></rich:column>
                 <rich:column><h:outputText value="#{varUser.lastname}" /></rich:column>
                
                 </rich:dataTable>
                
                 <rich:spacer height="8" />
                
                 <rich:datascroller id="dslUsers" for="tblUsers" maxPages="50" rendered="#{users.rowCount > 0}"/>
                
                </h:form>
                
                
                <h:form id="frmUserInfo">
                
                 <a4j:commandButton value="Update" action="#{usermanager.updateUser}" reRender="tblUsers, tplUserInfo" ></a4j:commandButton>
                
                 <rich:tabPanel id="tplUserInfo" switchType="client">
                
                 <rich:tab label="Personal Information">
                
                 <h:panelGrid columns="2">
                
                 <h:outputText value="First Name 1:" />
                 <s:decorate>
                 <h:inputText value="#{usermanager.selectedUser.firstname}" required="true">
                 <s:validate/>
                 </h:inputText>
                 </s:decorate>
                
                <h:outputText value="First Name 2:" />
                <h:outputText value="#{usermanager.selectedUser.firstname}" />
                
                 <h:outputText value="Middle Name:" />
                 <s:decorate>
                 <h:inputText value="#{usermanager.selectedUser.middlename}" required="true">
                 <s:validate/>
                 </h:inputText>
                 </s:decorate>
                
                 <h:outputText value="Last Name:" />
                 <s:decorate>
                 <h:inputText value="#{usermanager.selectedUser.lastname}" required="true">
                 <s:validate/>
                 </h:inputText>
                 </s:decorate>
                
                 </h:panelGrid>
                
                 </rich:tab>
                
                 </rich:tabPanel>
                
                </h:form>
                
                


                Steps...

                1. Click on rows in the datatable. It should should change the data in the tabs with each row clicked
                2. Clear out the data on the Middle Name field
                3. Hit Update
                4. The error Message "value required" will appear for the Middle Name Field
                5. Click on a new record in the datatable
                6. The only fields that update now are the Middle Name field and the First Name 2 field, the other fields do not update, BUT the bean information is correct....

                Is this a bug with the Validation framework and Input Box?

                • 5. Re: Validation and refresh problems...
                  Casey Boyd Novice

                  Can anyone help out on this?

                  Is this a bug? Am I doing something wrong?

                  Do I need to post the backing bean?

                  • 6. Re: Validation and refresh problems...
                    Lars-Erik Lis Newbie

                    We're having the exact same problem... we have an inputtext with required="true" and when validation error is received and when we click on a new element in our datatable some values aren't updated, except the ones that were submitted and caused the validation error..

                    Would be really helpful if someone could help!

                    • 7. Re: Validation and refresh problems...
                      Casey Boyd Novice

                      If someone else is getting this....that makes me feel a little better...

                      Can anyone help here?

                      For some reason, if Validation fails, the input boxes that DO NOT fail are not getting updated through AJAX....

                      Anyone?

                      Bueller?

                      Sorry, couldn't help my self... :)

                      • 8. Re: Validation and refresh problems...
                        Casey Boyd Novice

                        My last bump before I let this fall into oblivion...

                        :)

                        • 9. Re: Validation and refresh problems...
                          Lars-Erik Lis Newbie

                          We've come up with a solution conerning the field updates... or actually two different ones:

                          Alternative 1 (the best one in our opinion):
                          We have a datatable filled with rows, when a row is clicked the fields should be updated. When a validation error occured, the fields that didn't cause a validation error didn't get updated.
                          1. The closest parent to the fields (in our case, a panelgrid) has a binding to the backing bean.
                          2. In the action method of the onrowclick we start off by ensuring ourselves that the fields CAN be updated by clearing the submittedValue and the value of the UIComponent. It seems that these are not cleared, as they should be??

                          List<UIComponent> fields = getFormPanelGrid().getChildren();
                          for(UIComponent c : fields) {
                           if(c instanceof HtmlInputText) {
                           ((HtmlInputText)c).setSubmittedValue(null);
                           ((HtmlInputText)c).setValue(null);
                           }
                          }


                          This works out fine for us.

                          Alternative 2:
                          Clear these properties of the UIComponent in the validator. If you have required="true" I guess alt.1 is the better since you don't have any obvious way to clear these values.


                          I hope it works out for ya!

                          • 10. Re: Validation and refresh problems...
                            arjan tijms Novice

                            It seems though that this is still a problem. I'm using a fairly recent version of RichFaces (3.3.1) on Jboss AS 5.1.

                             

                            Just like the other posters, I have a page with 2 forms. On the second form I have an a4j:commandButton, with a reRender attribute set to rerender fields in the first form.

                             

                            As long as I have not posted the first form, pressing the a4j:button in the second form works perfectly. All the fields always get updated. However, as soon as I do post the first form AND this result in a validation error, then pressing the a4j:button does not longer update all fields in the first form.

                             

                            In my case however, this only concerns input fields (h:inputText and h:inputTextarea). Strict output only components (h:outputText and h:dataTable with only h:outputTexts) still rerender correctly. As soon as I change an h:inputText to an h:outputText, it updates again. Therefor I'm pretty sure I don't have any of the IDs wrongly spelled orso. Contrary to what others post it doesn't seem to be affected by which inputs do or do not pass validation.

                             

                            I'm going to try one of the solutions involving 'clearing' the input components (see also http://seamframework.org/Community/NoRerenderAfterValidationFailed), but I wonder if one of the rich faces devs could react on this issue.

                             

                            Thanks in advance!

                            • 11. Re: Validation and refresh problems...
                              henk de boer Master

                              It's indeed still a problem.

                               

                              I wonder, is this by design somehow or just a RichFaces bug? In case it's by design, maybe the documentation should be more clear about this? I spent days(!) a year ago to find the source of this and apparently it's still a problem for people after all this time.

                               

                              If it's by design, maybe RichFaces could log a message, something like:

                               

                              "The form on which component 'xyz' is attempted to be re-rendered has already been submitted. RichFaces does not re-render components in forms that have been submitted."

                               

                              Or something like that of course

                              • 12. Re: Validation and refresh problems...
                                Nick Belaevski Master

                                Hi,

                                 

                                This is really a behavior specific to JSF: http://ishabalov.blogspot.com/2007/08/sad-story-about-uiinput.html . You can replace a4j:commandLink components with h:commandLink - result will be just the same. As a workaround you can try clearing the whole component tree from action method instead of resetting states of the particular inputs.

                                • 13. Re: Validation and refresh problems...
                                  henk de boer Master

                                  nbelaevski wrote:

                                   

                                  Hi,

                                   

                                  This is really a behavior specific to JSF: http://ishabalov.blogspot.com/2007/08/sad-story-about-uiinput.html . You can replace a4j:commandLink components with h:commandLink - result will be just the same. As a workaround you can try clearing the whole component tree from action method instead of resetting states of the particular inputs.

                                   

                                  The link you gave explains the issue very well. Thanks! I think I have indeed stumbled upon that very behavior in a non a4j/richfaces setup before.

                                   

                                  Nevertheless, since the user explicitly declares that he wishes some component to be re-rendered, wouldn't it be expected by the user if RichFaces would clear this state first? For compatibility with existing code this might even be done via a separate attribute.

                                   

                                  e.g.

                                   

                                  <a4j:commandButton reRenderFromSource="someID" ... >

                                   

                                  or

                                   

                                  <a4j:commandButton reRender="someID" forceValueEvaluation="true" ... >

                                   

                                  What do you think?

                                  • 14. Re: Validation and refresh problems...
                                    Ilya Shaikovsky Master
                                    It's better to resolve this at JSF spec level by filling RFC there. Our approach is not to change functionality described in JSF spec but extend using standard extension points. From the point of view of your case it sounds reasonable. But as the submitted value needed in order to fire valueChangeEvent - such functionality will conflict with standard JSF functionality in its current state.
                                    1 2 Previous Next