1 Reply Latest reply on Nov 30, 2011 5:25 AM by Jacob Clarkson

    Validation of multiple <rich:listShuttle> items

    Jacob Clarkson Newbie

      Hi there,

       

      I have a requirement where a user must select at least one item from three <rich:listShuttle> elements, i.e. two <rich:listShuttle> elements may be empty but not all three.

       

      What is the best way of validating this within the RichFaches / JSF framework?

       

      Many thanks.

        • 1. Re: Validation of multiple <rich:listShuttle> items
          Jacob Clarkson Newbie

          I have now resolved this issue.

           

          In my validation I was able to get the value as follows; I needed to check that the a collection of three <rich:listShuttle> elements had at least one element selected between them, I acheived this as follows.

           

          ArrayList selectedElements1 = (ArrayList) this.availableElementsShuttle1.getTargetValue();
          ArrayList selectedElements2 = (ArrayList) this.availableElementsShuttle2.getTargetValue();
          ArrayList selectedElements3 = (ArrayList) this.availableElementsShuttle3.getTargetValue();
          
          if (selectedElements1 != null && selectedElements1.isEmpty()
                  && selectedElements2 != null && selectedElements2.isEmpty() 
                  && selectedElements3 != null && selectedElements3.isEmpty()) {
              // throw ValidatorException as all the listShuttle elements are empty
          }
          

           

          The availableElementsShuttlex Objects are UIListShuttle instances bound to <rich:listShuttle> elements in the XHTML via the binding attribute. A hidden field was used with a validator attribute which points to a method which houses the code above.