[jboss-user] [JBoss Seam] - Re: please help me out of this problem

fernando_jmt do-not-reply at jboss.com
Sun Sep 2 18:43:04 EDT 2007


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>
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4080334#4080334

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4080334



More information about the jboss-user mailing list