-
1. Re: please help me out of this problem
mnrz Aug 30, 2007 8:37 AM (in response to mnrz)#{userRegister.user} always returns value "com.epd.search.entity.User@2f8"
even after I set the user to "new User()" it won't change !!! -
2. Re: please help me out of this problem
mnrz Sep 1, 2007 8:58 AM (in response to mnrz)my User's scope is SESSION is this the issue which cause this problem?
because I just read somewhere in seam reference about @Role that we can define many roles for an entity but I don't know how to use them? -
3. Re: please help me out of this problem
mnrz Sep 2, 2007 3:24 AM (in response to mnrz)I had this problem in another page and after binding that component it worked but here I have 6 text fields I don't want to bind all of them.
-
4. Re: please help me out of this problem
fernando_jmt Sep 2, 2007 6:43 PM (in response to mnrz)I would use a @Factory.
Java:@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"; @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); user = userDao.load(selectedUsername); logger.debug("test:"+ user.getUsername()); } return user; } public void userListValueChanged(ValueChangeEvent event) { try { selectedUsername = (String) event.getNewValue(); } catch (Exception e) { e.printStackTrace(); } } }
Facelet:<h:panelGroup id="exportUser"> <h:outputLabel id="Username" <h:inputText value=#{user.username}/> <h:outputLabel id="Whatever" <h:inputText value=#{user.whateverProperty}/> <h:outputLabel id="userL" value="#{bundle['userDefination.group']}" for="groupMenu" /> <t:selectOneMenu id="userMenu" required="false" value="#{userRegister.selectedUsername}" valueChangeListener="#{userRegister.userListValueChanged}" onchange="submit(this)" > <f:selectItem itemLabel="New User ..." itemValue="0" /> <f:selectItems id="userList" value="#{userRegister.allUsers}" /> </t:selectOneMenu> </h:panelGroup>
-
5. Re: please help me out of this problem
mnrz Sep 3, 2007 4:41 AM (in response to mnrz)fernando,
really thanks for your nice solution, it worked fine, but another problem
when I select a user the information is displayed correctly, now consider I am changing some info say, address or contact number, how to manage this changed data at server and synchronize the changed User with the database? because the outjected with @Factory only set an attribute with stateless scope and now how to send back the new data to the server?
first, I tried to add @In for the user as follows:@In("tempUser") private User user; // consider @Factory's value is "tempUser" @Factory(value="tempUser",scope=STATELESS) public User initUser(){ //..... }
but it didn't work
any solution?
thanks -
6. Re: please help me out of this problem
fernando_jmt Sep 3, 2007 8:37 AM (in response to mnrz)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(); } } } }
-
7. Re: please help me out of this problem
mnrz Sep 3, 2007 8:56 AM (in response to mnrz)yes, but saveCurrentUser() that you declared only updates the instance variable user and the changes maded by user at client is not visible here. in other words, when I click on submit the changes I've made, not binded to any variable at server-side.
I'm not sure I could clarify myself or not -
8. Re: please help me out of this problem
fernando_jmt Sep 3, 2007 8:59 AM (in response to mnrz)Did you try it? Because I have the same case (I wrote) working in my application.
-
9. Re: please help me out of this problem
fernando_jmt Sep 3, 2007 9:01 AM (in response to mnrz)Also take into account the last change I did regarding the reloading of the user, because if a new instance of the same user is reloaded every time, then you don't expect to have the same reference instance variable updated.
-
10. Re: please help me out of this problem
mnrz Sep 3, 2007 9:58 AM (in response to mnrz)thanks Fernando, it works fine :)
with relaod, it works, but would you please tell me how this works?
as I understood, this @Factory will be called when at client-side an attribute of that name is referred (for example "tempUser")
and "relaod" flag compels loading the user only when my combobox has been changed.
Am I right?
thank you again for your nice solution. -
11. Re: please help me out of this problem
fernando_jmt Sep 3, 2007 11:12 PM (in response to mnrz)Yes your'e right.
STATELESS @Factory means it will be called every time the name is referenced in the page. In this case returning the already instantiated class.
And yes, the value change listener is invoked when the value is changed in the selectbox, enabling the @Factory method to reload with the new username. -
12. Re: please help me out of this problem
srpantano Sep 5, 2007 2:37 PM (in response to mnrz)Thank you!
Work well!@Factory(value = "license", scope=ScopeType.STATELESS)
-
13. Re: please help me out of this problem
mnrz Oct 9, 2007 2:06 AM (in response to mnrz)Hi Fernando
sorry to revive this thread, but I have a problem in the above SB
I don't know why changes to fields at client-side is not being seen at server-side. I mean when a user changes an item say, Phone no, and press the Save button at server-side I can see the same value that field already had and new value entered by user has gone!!!
and another strange thing is that, only changes to last item will be applied!!! for example, if I change the position of Phone No to last item, afterwards it will work but the other items don't!!!
do you know what happens here?
first I tried to bind the components to its server items but the problem remains.
thanks so much