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>@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();
}
}