3 Replies Latest reply on Aug 3, 2011 4:49 PM by bleathem

    Problem creating SelectItems

    bleathem

      For the orderingList, I prototyped the functionality using a nested f:selectItems component, as in:

      [example 1]:
                  <rich-input:orderingList id="orderingList" value="#{richBean.values}">
                      <f:selectItems value="#{richBean.values}" var="item"  itemValue="#{item}" itemLabel="#{item.title}" />
                      <f:converter converterId="EntityBeanConverter" />
                  </rich-input:orderingList>
      

       

      Now that I have that working, I want to move the item definition into the ordering list itself as in:

      [example 2]:
                  <rich-input:orderingList id="orderingList" value="#{richBean.values}" itemValues="#{richBean.values}" var="item" itemValue="#{item}" itemLabel="#{item.title}" >
                      <f:converter converterId="EntityBeanConverter" />
                  </rich-input:orderingList>
      

      (Don't worry, the itemValues is there temporarily as I get this working!)

       

      Now to generate the selectItem objects, I wanted to re-use as much of the existing code as possible, so I created an interface called "SelectItemsInterface" (for lack of a better name), and adapted the SelectUtils class to add the component itself to the iterator if the component implements this interface.  This is done as follows:

          public static Iterator<SelectItem> getSelectItems(FacesContext context, UIComponent component) {
              Iterator<UIComponent> children = component.getChildren().iterator();
              if (component instanceof SelectItemsInterface) {
                  Iterator<UIComponent> self = Iterators.singletonIterator(component);
                  children = Iterators.concat(self, children);
              }
              Iterator<SelectItem> iterator = new SelectItemsIterator(context, children);
              return iterator;
          }
      

       

      The process for generating the selectItems from the orderingList tag is almost identical to the process of creating selectItems from the f:selectItems tag, except the values come from the itemValues tag for now.

       

      This works well, in that the selectItem objects are created with the iterator, and I'm able to render the page.

       

      The problem comes about when I submit the page.  In [example 1] above everything works as expected.  However, in [example 2] the setter of the backing bean is never called.  I can't for the life of me figure out what would be interfering with the call to the backing bean setter.  Everything is the same - the deDecode method, getConvertedValues, etc.

       

      Is there something about the selectItem generation on postback that interferes with calling the setter of the backing bean?  Any insight would be appreciated!

       

      Thanks

        • 1. Re: Problem creating SelectItems
          jbalunas

          Lets discuss at the team meeting today - can you add to the agenda?

          • 2. Re: Problem creating SelectItems
            bleathem

            Update: (after wrestling with the Eclipse debugger for a while)

             

            When I submit using [example 2], the UIInput#validate method evaluates a false on the isValid() call, but with [example 1] the isValid call evaluates to true.

             

            I need to attach more sources to figure out why, but this is something!

            • 3. Re: Problem creating SelectItems
              bleathem

              Ok, I have the source of the problem:

              The UISelectMany#validateValue checks to make sure the submitted value is one of the selectItem values.  However, it isn't aware that the OrderingList component is a source of selectItems, so it evaluates to false.

               

              To correct the problem, I'll have to override the validateValue method for my component.  Should be a simple enough fix.