0 Replies Latest reply on Mar 31, 2011 5:26 AM by m23

    Two dependent selectManyListboxes: "Value is not a valid option" error

    m23
      Dear all!

      I'm trying to implement two selectManyListboxes "List-A" and "List-B".
      As soon as the user changes the selection of "List-A", the content of "List-B" will be reloaded from the database (with the "List-A"-selection as a filter).

      Now this works great until the user also selects a value in "List-B". If he then decides to change the value in "List-A" he'll get the following error:

      "Validation error: Value is not a valid option".

      As far as i understand (with the help of Google ;-) I've got a problem with the fact that the content of ListB is different before the page submit and after the page submit (as ListB is reloaded with other values). Thus the selectedItem of ListB is not valid anymore (as it may not even be present in the reloaded list). Could you guys help me solve this problem?

      Here's my simplified code:

      ----------------------------------------------------------------------------
      VIEW
      ----------------------------------------------------------------------------

      <h:selectManyListbox
         id="ListA"
         valueChangeListener="#{controller.listAValuesChanged}"
         value="#{controller.selectedItemsListA}">
        
      <f:selectItems value="#{controller.listA}"/>

      </h:selectManyListbox>

      <h:selectManyListbox
         id="ListB"
         value="#{controller.selectedItemsListB}">
        
      <f:selectItems value="#{controller.listB}"/>

      </h:selectManyListbox>


      ----------------------------------------------------------------------------
      CONTROLLER
      ----------------------------------------------------------------------------

      private List<SelectItem> listB= null;
      private List<String> selectedItemsListB = null;

      public List<String> getSelectedItemsListB() {
         return selectedItemsListB;
      }

      public void setSelectedItemsListB(List<String> selected) {
         this.selectedItemsListB = selected;
      }

      public List<SelectItem> getListB(){
         listA = loadListBFromDatabase(getListBFilter());
         return selectItem;
      }


      // Called once ListA has changed
      public void listAValuesChanged(ValueChangeEvent e) {
                
         setListBFilter(e.getNewValue());

      }

      ----------------------------------------------------------------------------