0 Replies Latest reply on Dec 28, 2009 2:28 PM by bora bora

    Seam component binding with primitive wrapper

    bora bora Newbie

      Hi Seam community,

      I have recently come across a Seam component binding problem, which I have managed to work around, but I would like to receive comments as to the root cause of this behaviour. I just don't have the time to get into Seam source code at the moment to debug myself so if anybody knows any answers or have any ideas, it would be appreciated.


      Seam version: 2.1.2


      Basically, I have a manager class which owns a collection of Integer objects (primitive wrapper, List<Integer>). And I need to be able to present this list of Integer objects to the user as a row of text boxes (i.e. inputText) while these text boxes are bound to the Integer objects. However, it seems that I am not able to bind the data entered via the Facelet view to the values kept in the list of Integer's. But when I use another wrapper to hold the Integer objects then it works. In addition, there are multiple manager objects in a list too, but I am not sure it is related. Is this about autobox/unbox..? It seems like when the 'value' attribute of inputText refers to the Integer object but not a property of an object which happens to be of Integer type then the Integer is simply handled as a primitive (i.e. unboxed). Any comments are appreciated.


      Below are some code snippets to describe what's intended.


      Thanks,
      Bora.


      /* Not working */
      @Name(itemListManagerList)
      public class ItemListManagerList {
          List<ItemListManager> itemsListManagers;
      }
      
      @Name(itemListManager)
      public class ItemListManager {
          List<Integer> items;
      }
      
      /* Not working view */
      <a:repeat value="#{itemListManagerList.itemListManagers}" var="itemListManager">
          <s:decorate id="itemListManagerDecoration" template="layout/edit.xhtml">
              <ui:define name="label">#{someLabel}</ui:define>
              <a:repeat value="#{itemListManager.items}" var="item">
                  <h:inputText id="itemTxt" required="true" value="#{item}" />
              </a:repeat>
          </s:decorate>
      </a:repeat>
      


      /* Working */
      @Name(itemListManagerList)
      public class ItemListManagerList {
          List<ItemListManager> itemsListManagers;
      }
      
      @Name(itemListManager)
      public class ItemListManager {
          List<ItemValue> items;
      }
      
      public class ItemValue {
          Integer value;
          public ItemValue(){}
          public ItemValue(Integer value) {
              this.value = value;
          }
          // getters and setters etc.
      }
      
      /* Working view */
      <a:repeat value="#{itemListManagerList.itemListManagers}" var="itemListManager">
          <s:decorate id="itemListManagerDecoration" template="layout/edit.xhtml">
              <ui:define name="label">#{someLabel}</ui:define>
              <a:repeat value="#{itemListManager.items}" var="item">
                  <h:inputText id="itemTxt" required="true" value="#{item.value}" />
              </a:repeat>
          </s:decorate>
      </a:repeat>