I have a common "search, display results, do something with the selected one" scenario. I am using page scope for the @DataModel. The problem occurs when I attempt to perform an action (using parametrized method binding) on the selected item as, for some reason, the selected item is always null.
Here's the whole thing:
@DataModel(scope=ScopeType.PAGE)
private List<Item> items;
<rich:dataTable id="items" var="item" value="#{items}" rendered="#{items.size > 0}">
...
<s:link id="voteForItem" value="Vote"
action="#{itemList.addVote(item)}" />
public void addVote(Item i) {
assert currentUser != null;
Vote vote = new Vote(i, currentUser);
entityManager.persist(vote);
}
"Item i" passed to addVote is always null, so it always throws an exception (as it requires a non-null value). Changing the @DataModel scope to CONVERSATION fixes this, but I do not want to do that as it interferes with other aspects.
I double and triple checked if I am doing something wrong, but I can't see anything.
As SiA states:
The page context is capable of propagating data from the Render Response phase of the JSF
life cycle through at least the ensuing Invoke Application phase on a postback, then on
to the Render Response phase if the same view is rendered again without a redirect.
Any clues what might be going on? Any insight is greatly appreciated...