I still get confused about the PAGE
and the CONVERSATION
(temp) scope. Maybe I get some help here.
As fas as I know, variables outjected to the PAGE
scope live as long as the user only postbacks the same page. The temporary CONVERSATION
scope instead even survives a redirect to the next page.
Here is a little example with two effects that are confusing to me:
First, component and outjections are in CONVERSATION
scope and the tempUser
data is displayed in a jsf page. But in the save method called from that jsf-page, the injected tempUser
is null. Why?
Second, if I do the same but change component and @In/@Outs scopes to PAGE
scope, the tempUser
gets correctly injected on postback - but gets not saved, for wathever reason, although even the super.update()
-method on userHome
gets called. Or is there a problem in using the homeEntities that ways (the idea iwa to use them only as DAO wrapper)?
@Name("userAction")
@Scope(ScopeType.CONVERSATION)
public class UserAction implements Serializable {
private static final long serialVersionUID = -4852371546895918692L;
@In(create = true)
private UserHome userHome;
@Out(scope = ScopeType.CONVERSATION)
@In(required = false,scope = ScopeType.CONVERSATION)
User tempUser;
@RequestParameter
private Long userId;
@Factory("tempUser")
public User getUser() {
if (tempUser == null) {
userHome.setUserId(userId);
tempUser = userHome.getInstance();
userHome.clearInstance();
}
return tempUser;
}
public void save() {
userHome.setInstance(tempUser);
userHome.update();
}
}
The xhtml contains a a:form with
<a:commandButton
id="update"
styleClass="button admin"
action="#{userAction.save}"
value="#{messages['user.action.update']}"/>
Thanks for replies. Sorry, if this is two problems in one.