0 Replies Latest reply on Jul 17, 2006 6:01 AM by Venkat Rao

    @DataModelSelection behavior : bug or feature ?

    Venkat Rao Newbie

      When does a variable annotated as @DataModelSelection get injected? Is it only when a row in the <h:dataTable> is selected? Or does it get initialized whenever there is a postback, even from a control outside the <h:dataTable>?

      I am observing that in addition to the first case above, the second is also true. Even when an action listener is invoked in response to a link outside the <h:dataTable> element, the @DataModelSelection variable is getting initialized to the first element of the @DataModel.

      Is my observation correct? Is that the expected behavior? That is causing unexpected behavior in my code. I am attaching my sources below to better illustrate.

      Thanks,

      -- venkat


      <h:form>
      
       <s:link value="Up one level"
       rendered="#{folderNavigator.curFolder != null}"
       action="#{folderNavigator.upOneLevel}" />
      
       <h:dataTable var="folder" value="#{folderList}" >
       <h:column>
       <s:link value="#{folder.folderName}"
       action="#{folderNavigator.selectFolder}" />
       </h:column>
       </h:dataTable>
      
      </h:form>

      In the listing above, "folderList" is a @DataModel, declared and used in the folderNavigator stateful session bean, which is given below:
      @Stateful
      @Scope(SESSION)
      @Name("folderNavigator")
      public class FolderNavigatorAction implements FolderNavigator, Serializable
      {
       @DataModel
       private List<Folder> folderList;
      
       @DataModelSelection
       private Folder curFolder;
      
       @Factory("folderList")
       public void retrieveFolderList() {
      
       if (curFolder == null) {
       folderList = rootFolderList; // Initialized in constructor
       }
       else {
       folderList = curFolder.getChildFolders();
       }
       }
      
       public void selectFolder() {
       retrieveFolderList();
       }
      
       public void upOneLevel() {
       curFolder = curFolder.getParent();
       retrieveFolderList();
       }
      }

      When the upOneLevel() method is called, curFolder is automatically injected with the first element of folderList, even though it was not invoked in response to a data model selection.