1 Reply Latest reply on Mar 21, 2007 6:06 PM by Yevgen Bushuyev

    @DataModelSelection defaults to first value in model??

    Eric De Prez Newbie

      Very simple use case. I've a DataModel, initialized through @Factory. It is never empty at first.

      private List<Item> items;
      @DataModelSelection @Out(required=false)
      private User selItem;

      I'd like to invite the user to select an item in the list when no selection is active. But my selItem is never empty at first page hit! It defaults to first value in DataModel! So it's just like the user has already made a selection. Which is wrong!

      Is there a reason why this is working like this? Or maybe I'm missing something. It's so simple it's very frustrating.

      Also, when I add
      private int selIndex;

      I get the following exception when deploying:
      java.lang.IllegalStateException: Multiple @DataModelSelection fields for: items

      Is this expected behaviour?


        • 1. Re: @DataModelSelection defaults to first value in model??
          Yevgen Bushuyev Newbie

          I met the same problem, but in slightly different context - i have a CRUD SFSL and it's instance member after creation was overwritten with new value:

          public class ItemEditor implements ItemEditorLocal{
           private Item item = new Item();
           public void persist() {
           this.item = new Item();

          by this i wanted to clean the form which displays current item. But instead i got my form populated with recently entered data. Even after killing all cookies and refreshing the page it was filled. I was completely baffled!

          But it appears that most likely the problem is caused by javax.faces.model.ListDataModel - it sets rowIndex to 0 when it has some data and then when injectDataModelSelections is being called on a component the first element in a datamodel is picked up and injected into member annotated with @DataModelSelection... hardly it was expected behaviour...

          btw, there is a astounding code in injectDataModelSelection:
           if (null!=null)
           setFieldValue( bean, null, name, wrapper.getWrappedData(dataModelAnn, dataModel) ); //for PAGE scope datamodels (does not work for properties!)

          i mean null!=null ... what is that?

          wbr, eugen.