[jboss-user] [JBoss Seam] - Re: please help me out of this problem
fernando_jmt
do-not-reply at jboss.com
Mon Sep 3 08:37:47 EDT 2007
Yes, you're right, "user" is stateless, but take a look what return initUser method. It returns the reference to the instance variable "user".
So, this should work:
| private User user;
| public void saveCurrentUser() {
| userDao.update(user);
| }
|
BTW, I improved a bit my last example (avoiding several loading roundtrip):
|
| @Stateful
| @Name("userRegister")
| @Scope(ScopeType.SESSION)
| public class UserRegisterAction implements UserRegister {
|
| private Log logger = LogFactory.getLog(UserRegisterAction.class);
|
| private User user;
| private String selectedUsername = "0";
| private boolean reload;
|
|
|
| @Factory(value = "user", scope = ScopeType.STATELESS)
| public User initUser() {
| if(selectedUsername.equals("0")){
| logger.debug("new user");
| user = new User();
| }else{
| logger.debug("edit:"+ selectedUsername);
| if(reload) {
| user = userDao.load(selectedUsername);
| reload = false;
| logger.debug("test:"+ user.getUsername());
| }
| }
| return user;
| }
|
| public void userListValueChanged(ValueChangeEvent event) {
|
| try {
| selectedUsername = (String) event.getNewValue();
| reload = true;
|
| } catch (Exception e) {
| e.printStackTrace();
| }
| }
|
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080477#4080477
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080477
More information about the jboss-user
mailing list