10 Replies Latest reply on Feb 25, 2009 5:10 PM by gjeudy

    ListShuttle and validation

    gjeudy

      Hi,

      I'm trying to validate values in my listShuttle. The listShuttle is working fine without any validation.

      <rich:listShuttle id="toRelShuttle"
       targetValue="#{relatedToInstances}"
       sourceValue="#{unrelatedToInstances}"
       targetCaptionLabel="Related Ref Domain Instances"
       sourceCaptionLabel="Unrelated Ref Domain Instances"
       fastOrderControlsVisible="false" orderControlsVisible="false"
       listsHeight="400px" sourceListWidth="400px" targetListWidth="400px"
       copyAllControlLabel="Relate All" copyControlLabel="Relate"
       removeAllControlLabel="Unrelate All" removeControlLabel="Unrelate"
       converter="#{my.web.converter.IdentifiableConverter}"
       var="domInstVO"
       validator="businessKeyBatchingValidator">
       <h:column>
       <f:facet name="header">
       <h:outputText value="Id" />
       </f:facet>
       <h:outputText value="#{domInstVO.referenceDomainInstance.id}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Name" />
       </f:facet>
       <h:outputText
       value="#{domInstVO.referenceDomainInstance.description}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Code" />
       </f:facet>
       <h:outputText
       value="#{domInstVO.referenceDomainInstance.codeValue}" />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Valid From Dt" />
       </f:facet>
       <h:inputText id="validFromDt"
       value="#{domInstVO.validityPeriod.validFromDate}"
       />
       </h:column>
       <h:column>
       <f:facet name="header">
       <h:outputText value="Valid To Dt" />
       </f:facet>
       <h:inputText id="validToDt"
       value="#{domInstVO.validityPeriod.validToDate}"
       />
       </h:column>
       </rich:listShuttle>
      .

      I'm using Richfaces 3.2.1.GA. I notice that the JSF validator validate() method is called twice the first time the value passed is a List representing what I have in sourceValue, the 2nd time targetValue. That is a little ackward but I can live with that.

      However, if I change a value in my h:inputText on one of the rows for example, I submit and this changed value is not reflected in JSF validator validate() method.

      PS: I properly implemented equals() and hashCode() on my value object.

      Is this is a bug?

      Thanks,
      -Guillaume

        • 1. Re: ListShuttle and validation
          nbelaevski

          Hello Guillaume,

          Looks like a bug. Please try 3.3.0.GA.

          • 2. Re: ListShuttle and validation
            adubovsky

            Hello,

            I have verified this issue in 3.3.1.SNAPSHOT version. Behaviour is some different from Guillaume described one: validator is called only once - for sourceValue. And changed value is not reflected in JSF validator validate() method - here all as was described by Guillaume.

            Bug in JIRA was opened: https://jira.jboss.org/jira/browse/RF-6423

            • 3. Re: ListShuttle and validation
              gjeudy

              Behavior is the same in 3.3.0.GA, except that validate() is called only once with an Object[2] array, pos 0 is source list, pos 1 is target list.

              There seems to be some code that attempts to get the new submitted values but I can confirm that it doesnt work by stepping through it in my debugger. The "new" values are exactly the same as the old values.

              Referring here to: public void validate(FacesContext context) in UIListShuttle class.

              • 4. Re: ListShuttle and validation
                adubovsky

                Sorry, it was a a mistake in my code. Yes, only one problem - changed value of input is not reflected in validator validate() method.

                I have correct JIRA issue. Thanks.

                • 5. Re: ListShuttle and validation
                  adubovsky

                  Sorry again,

                  You should use validator for input in order to validate its value. ListShuttle validator get Object[2] array with source and target ArrayList's. But in this lists objects from datamodel are stored, so they are not updated with newly inputted values. New values will be passed to the ListShuttle validator only after the next request.

                  So this is not a bug and issue was closed.

                  • 6. Re: ListShuttle and validation
                    gjeudy

                    ok can you tell me in which case listShuttle validator would be useful if new inputted values are not reflected in the lists ?

                    • 7. Re: ListShuttle and validation
                      adubovsky

                      There are many cases...

                      E.g. checking count of rows in source and target lists, order of rows in target list and many other dependent on specific of your application.

                      • 8. Re: ListShuttle and validation
                        gjeudy

                        ok you got a point. Here's my usecase I would to do row level validation, the editable fields on the row are just part of that validation therefore it doesn't make sense to plug a validator directly on one of the fields.

                        The effect would be repeated calls to that validator for every row and then I don't see an easy way to retrieve the matching row from the JSF UI Tree (from within my validator). Most importantly all editable row values should be accessible from the validator.

                        If you have any advice on how to achieve this with a listShuttle I would be pleased to hear about it.

                        If the listShuttle validator could have all the latest submitted values that would be the best solution for my usecase. If that is not a bug can it be filed as a new feature request ?

                        Thanks,
                        -Guillaume

                        • 9. Re: ListShuttle and validation
                          nbelaevski

                          Hello Guillaume,

                          This makes sense, I've posted RFC: https://jira.jboss.org/jira/browse/RF-6438

                          • 10. Re: ListShuttle and validation
                            gjeudy

                            Thanks !

                            In the meantime do you have any workarounds to propose?

                            It doesnt seem like I can call HtmlListShuttle.invokeOnComponent(), by the way that works perfectly for a regular dataTable (not so for a listShuttle) and it enables me to retrieve a submitted value in a UIData structure.

                            Since HtmlListShuttle doesn't give me any alternative API (that I can see) I feel like I may be forced to inspect the javascript variables for listShuttle and use that to fire an adhoc AJAX style validation.

                            Any other suggestions?

                            PS: I want to avoid doing that validation during the INVOKE APPLICATION phase because then the values are applied to the model. I'm using Seam with conversations, the entities in my listShuttle are managed in the persistence context therefore would be marked dirty and automatically flush regardless of the validation outcome...

                            Thanks,
                            -Guillaume