[jboss-user] [JBoss Seam] - why Factory method is calling more than once?
mnrz
do-not-reply at jboss.com
Mon Oct 15 02:06:13 EDT 2007
Hi
I have a factory method for a field User in my SB, and I want to know why this method is calling as many time as the number of User's field?
in my case, the User has 12 fields do this method is called 12 times whereas I load it once from database ?
please take a look at following code:
| @Factory(value = "tempUser", scope = ScopeType.STATELESS)
| public User loadUser() {
| if(reload || tempUser == null) {
| if(selectedUsername.equals("0")) {
| logger.debug("instantiating a new User");
| tempUser = new User();
| verifyPassword = password = "";
| selectedGroup = 0L;
| }else{
| logger.debug("loading User with username '"+selectedUsername+"'");
| tempUser = userDao.load(selectedUsername);
| if(tempUser.getGroup() != null)
| selectedGroup = tempUser.getGroup().getId();
| verifyPassword = password = tempUser.getPassword();
| selectedRoles = new ArrayList<String>();
| for(UserRole r : tempUser.getRoles()) {
| selectedRoles.add(r.getRoleName());
| }
| logger.debug(tempUser.toString());
| reload = false;
| //setInputValuesWithUser();
| }
| }
| return tempUser;
| }
|
|
as you see, at first the "reload" is true so the User will be populated from the database and then the reload will set to false, but at my XHTML page, no value will be displayed !!!!! however I can see all the User's value in the logs (produced by logger)
if I remove the line highlighted bu blue color reload = false; it will work fine but this method will be called 6 times and in app server console I can see that 12 times the EJB is selecting from database!!!
thank you very much in advance
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095089#4095089
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095089
More information about the jboss-user
mailing list