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
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to