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.


      -- venkat

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

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

      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.