10 Replies Latest reply on Oct 13, 2007 2:25 AM by Mohammad Norouzi

    binding attribute doesnt work with Seam?

    Mohammad Norouzi Novice

      Hi everybody,
      I have a SFSB in which I managed creating and editing user profile as follows:

      @Stateful
      @Name("userRegister")
      @Scope(ScopeType.CONVERSATION)
      public class UserRegisterAction implements UserRegister {
      
       private Log logger = LogFactory.getLog(UserRegisterAction.class);
      
       private User tempUser;
      
       private HtmlSelectOneMenu selectOneUser;
      
       private SelectItem[] allUsers;
       private ArrayList<SelectItem> allRoles;
       private SelectItem[] allGroups;
       private boolean newUser;
       private Long selectedGroup = 0L;
       private String selectedUsername = "0";
       private boolean reload = false;
       private UIInput username;
       private UIInput address;
       private UIInput contactNo;
       private UIInput mobilePhone;
       private String verifyPassword;
       private String password;
      
       @EJB
       private UserDao userDao;
       @EJB
       private GroupDao groupDao ;
      
      
       private List<String> selectedRoles;
       //rest of the codes...
      }
      


      the problem is when I press the "Save" button to apply changes the new values never submit to the server and they will remain intact.

      so I think the only way is to bind the items with its corresponding field at server-side but binding doesnt work!!

      it throws exception which means this identifier can not resolve

      javax.servlet.ServletException: /pages/main/userDifination.xhtml @57,77 binding="#{userRegister.username}": Target Unreachable, identifier 'userRegister' resolved to null
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
       org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
       org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
       org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
       org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
       org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:29)
       org.jboss.seam.servlet.SeamCharacterEncodingFilter.doFilter(SeamCharacterEncodingFilter.java:41)
      
      
      root cause
      
      javax.faces.el.PropertyNotFoundException: /pages/main/userDifination.xhtml @57,77 binding="#{userRegister.username}": Target Unreachable, identifier 'userRegister' resolved to null
       com.sun.facelets.el.LegacyValueBinding.isReadOnly(LegacyValueBinding.java:84)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:84)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:57)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:94)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:57)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:94)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:57)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:94)
       org.apache.myfaces.shared_impl.util.RestoreStateUtils.recursivelyHandleComponentReferencesAndSetValid(RestoreStateUtils.java:57)
       org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:96)
       org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
       org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
       javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
       org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
       org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
       org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:100)
       org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
       org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:29)
       org.jboss.seam.servlet.SeamCharacterEncodingFilter.doFilter(SeamCharacterEncodingFilter.java:41)
      
      
      


      here is a fragment of my xhtml file:
       <h:form id="userDifination">
       <br/>
       <h:panelGroup rendered="true" id="mainPanel">
       <!-- validateAll -->
       <h:panelGrid rendered="true" align="center" id="mainPanel2"
       rowClasses="rowTable1, rowTable2" headerClass="titleTable"
       footerClass="footerTable" styleClass="borderTable"
       captionClass="titleTable" columns="6" border="0" width="70%">
       <f:facet name="header">
       <h:outputLabel id="label1"
       value="#{bundle['userDifination.header']}" />
       </f:facet>
       <h:outputLabel id="userL"
       value="#{bundle['userDifination.selectUser']}" for="userMenu" />
      
       <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 rendered="true" id="userPanel2">
       </h:panelGroup>
       <h:panelGroup rendered="true" id="userPanel3">
       </h:panelGroup>
       <h:panelGroup rendered="true" id="userPanel4">
       </h:panelGroup>
       <h:panelGroup rendered="true" id="userPanel5">
       </h:panelGroup>
      
      
       <h:outputLabel id="userUserNameL"
       value="#{bundle['userDifination.username']}" rendered="true"
       for="userUserNameT" />
       <h:inputText id="userUserNameT" styleClass="textBox"
       binding="#{userRegister.username}" required="false"
       value="#{tempUser.username}" readonly="#{!userRegister.newUser}"/>
       <h:panelGroup rendered="true" id="userPanel">
       <span class="errors"><h:message for="userUserNameT" />
       </span>
       </h:panelGroup>
       <h:outputLabel id="userPasswordL"
       value="#{bundle['userDifination.password']}"
       for="userPasswordT" />
      
       <h:inputSecret id="userPasswordT" styleClass="textBox"
       value="#{userRegister.password}" />
       <h:panelGroup rendered="true" id="passPanel">
       <span class="errors"><h:message for="userPasswordT" />
       </span>
       </h:panelGroup>
       <h:outputLabel id="mobileL"
       value="#{bundle['userDifination.mobile']}" for="mobileT" />
       <h:inputText id="mobileT" styleClass="textBox"
       value="#{tempUser.mobileContact}" />
       <h:panelGroup rendered="true" id="mobilPanel">
       <span class="errors"><h:message for="mobileT" /> </span>
       </h:panelGroup>
      
       <h:outputLabel id="userVerifyPasswordL"
       value="#{bundle['userDifination.verifyPassword']}"
       for="userVerifyPasswordT" />
      
       <t:inputSecret id="userVerifyPasswordT" styleClass="textBox"
       value="#{userRegister.verifyPassword}" />
       <h:panelGroup rendered="true" id="verifyPanel">
       <span class="errors"><h:message
       for="userVerifyPasswordT" /> </span>
       </h:panelGroup>
      
       <h:outputLabel id="addressL"
       value="#{bundle['userDifination.address']}" for="addressT" />
       <h:inputText id="addressT" styleClass="textBox"
       value="#{tempUser.address}" />
       <h:panelGroup rendered="true" id="addressPanel">
       <span class="errors"><h:message for="addressT" /> </span>
       </h:panelGroup>
      
       <h:outputLabel id="phoneL"
       value="#{bundle['userDifination.address']}" for="phoneT" />
       <h:inputText id="phoneT" styleClass="textBox"
       value="#{tempUser.phoneNo1}" />
       <h:panelGroup rendered="true" id="phonePanel">
       <span class="errors"><h:message for="phoneT" /> </span>
       </h:panelGroup>
      
      
       <h:outputLabel id="roleL"
       value="#{bundle['userDifination.role']}" for="roleMenu" />
       <h:selectManyMenu id="roleMenu"
       title="#{bundle['userDifination.role']}"
       value="#{userRegister.selectedRoles}" >
       <f:selectItems value="#{userRegister.allRoles}" />
       </h:selectManyMenu>
       <h:panelGroup rendered="true" id="permissionPanel">
       </h:panelGroup>
      
       <h:outputLabel id="groupL"
       value="#{bundle['userDifination.group']}" for="groupMenu" />
       <h:selectOneMenu value="#{userRegister.selectedGroup}" id="groupMenu">
       <f:selectItems value="#{userRegister.allGroups}" />
       </h:selectOneMenu>
       <f:facet name="footer">
       <h:panelGrid columns="1" styleClass="scrollerTable2"
       align="center" width="20%"
       columnClasses="standardTable_ColumnCentered">
       <h:panelGroup rendered="true" id="buttonPanel">
       <input type="reset" name="_id1:_id20:_id38" value="Reset" />
       <h:commandButton type="submit" value="Back"
       action="#{userRegister.back}" />
       <h:commandButton type="submit" value="Save"
       action="#{userRegister.save}" />
       </h:panelGroup>
       </h:panelGrid>
       </f:facet>
       </h:panelGrid>
       <!-- validateAll -->
       <div align="center">
       <h:messages warnClass="textWarn" infoClass="textInfo"
       fatalClass="textFatal" errorClass="textError"
       globalOnly="true" />
       </div>
       </h:panelGroup>
       </h:form>
      


      I am using JBoss Seam v1.1.6
      is this a Seam issue or I've made a mistake somewhere ?

      thank you so much

        • 2. Re: binding attribute doesnt work with Seam?
          Mohammad Norouzi Novice

          thanks matt, but I couldn't see any question regarding binding a component,
          in both link, and also the second link is for 2 version of the Seam I am using 1.1.6 and at the moment I can't upgrade to version 2.

          thanks anyway

          • 3. Re: binding attribute doesnt work with Seam?
            Christian Bauer Master

            You can't bind to a CONVERSATION scoped backing component because the conversation context is not available in the RESTORE VIEW phase.

            • 4. Re: binding attribute doesnt work with Seam?
              Mohammad Norouzi Novice

               

              "christian.bauer@jboss.com" wrote:
              You can't bind to a CONVERSATION scoped backing component because the conversation context is not available in the RESTORE VIEW phase.


              thanks christian,
              I put this as a FAQ in wiki page


              • 5. Re: binding attribute doesnt work with Seam?
                Mohammad Norouzi Novice

                now that binding exception has been gone but new problem is that at server-side I get no changes and no value by binded components
                I put following log at my backing bean

                logger.debug(contactNo.getLocalValue()+" - "+contactNo.getSubmittedValue()+" - "+contactNo.getValue());
                


                but two first methods return null and the last one (getValue) returns the same value that the component was set already and no changes of the user will be applied, what's the problem here?

                • 6. Re: binding attribute doesnt work with Seam?
                  Mohammad Norouzi Novice

                  Hi friends,
                  there is something strange! I have 6 text box in my page
                  username, password, password verify, phone no, address, mobile no

                  astonishingly, when I press Save button to update changes, at server-side only changes to last text box is being seen and others remained intact and when I substitute another text box say "phone no" with the last one (change their position) again only changes to last text box (phone no) is visible and the others have the same value they already had

                  what's the problem? is this an issue with Seam?

                  thanks

                  • 7. Re: binding attribute doesnt work with Seam?
                    Mohammad Norouzi Novice

                    anybody can help me please?

                    • 8. Re: binding attribute doesnt work with Seam?
                      Stuart Douglas Master

                      Can you post the xhtml and the backing bean?

                      • 9. Re: binding attribute doesnt work with Seam?
                        Mohammad Norouzi Novice

                        the xhtml is already posted at first thread above and here is the backing bean:

                        @Stateful
                        @Name("userRegister")
                        @Scope(ScopeType.SESSION)
                        @Restrict("#{s:hasRole('Admin')}")
                        public class UserRegisterAction implements UserRegister {
                        
                         private Log logger = LogFactory.getLog(UserRegisterAction.class);
                        
                         private User tempUser;
                        
                         private HtmlSelectOneMenu selectOneUser;
                        
                         private SelectItem[] allUsers;
                         private ArrayList<SelectItem> allRoles;
                         private SelectItem[] allGroups;
                         private boolean newUser;
                         private Long selectedGroup = 0L;
                         private String selectedUsername = "0";
                         private boolean reload = false;
                         private UIInput username;
                         private UIInput address;
                         private UIInput contactNo;
                         private UIInput mobilePhone;
                         private String verifyPassword;
                         private String password;
                        
                         @EJB
                         private UserDao userDao;
                         @EJB
                         private GroupDao groupDao ;
                        
                        
                         private List<String> selectedRoles;
                        
                        
                         //constructors....
                         public UserRegisterAction() {
                         logger.debug("constructing UserRegisterAction...");
                        
                         }
                        
                         @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());
                         }
                         //setInputValuesWithUser();
                         }
                         }
                         return tempUser;
                         }
                        
                         //private methods...
                         private void loadAllRoles() {
                         List<ObjectMap> list = null;
                         try {
                         list = ActionUtil.getClassResourceBundle().getList(AccessRole.class, new java.util.Locale("en"));
                         } catch (Exception e) {
                         e.printStackTrace();
                         }
                        
                         if(list != null) {
                         allRoles = new ArrayList<SelectItem>();
                         for(int i = 0;i< list.size();i++) {
                         if(list.get(i).getValue() == null || list.get(i).getValue().equals(AccessRole.Unknown.name())) {
                         continue;
                         }
                         SelectItem item = new SelectItem();
                         item.setLabel(list.get(i).getMeaning());
                         item.setValue(list.get(i).getValue());
                         allRoles.add(item);
                         }
                         }
                         }
                        
                         @SuppressWarnings("unchecked")
                         private void loadAllGroups() {
                         List<Group> groups = groupDao.loadAll();
                         if(groups != null) {
                         allGroups = new SelectItem[groups.size()+1];
                         allGroups[0] = new SelectItem(new Long(0),"--not-specified--");
                         for(int i = 0;i< groups.size();++i) {
                         SelectItem item = new SelectItem();
                         item.setLabel(groups.get(i).getName());
                         item.setValue(groups.get(i).getId());
                         allGroups[i+1] = item;
                         }
                         }
                         }
                        
                         private void loadAllUsers() {
                         logger.debug("loading... " + userDao);
                         List users = userDao.load();
                         if(users != null) {
                         allUsers = new SelectItem[users.size()];
                         for(int i = 0; i < users.size();++i) {
                         SelectItem item = new SelectItem();
                         User u = (User) users.get(i);
                         item.setLabel(u.getUsername());
                         item.setValue(u.getUsername());
                         allUsers = item;
                         }
                         }
                         }
                        
                         private void saveNewUser() {
                         logger.debug("inserting....");
                         User existing =userDao.load(tempUser.getUsername());
                         if (existing == null) {
                         tempUser.setPassword(password);
                         tempUser.setGroup(groupDao.load(selectedGroup));
                         userDao.save(tempUser);
                         loadAllUsers();
                         FacesMessages.instance().add(FacesMessage.SEVERITY_INFO,"tempUser '"+tempUser.getUsername()+"' has been created successfuly");
                         tempUser = new User();
                         setNewUser(true);
                         selectedUsername = "0";
                         selectedRoles.clear();
                        
                         } else {
                         FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR,"User '#{userRegister.user.username}' already exists. please choose another username");
                         return;
                         }
                         }
                        
                         private void updateUser() {
                         logger.debug("merging....");
                         try {
                         tempUser.setPassword(password);
                         tempUser.setGroup(groupDao.load(selectedGroup));
                         tempUser.getRoles().clear();
                         for(String role: selectedRoles) {
                         tempUser.addRole(role);
                         }
                         userDao.merge(tempUser);
                         FacesMessages.instance().add(FacesMessage.SEVERITY_INFO,"'"+tempUser.getUsername()+"' has been updated successfuly");
                         } catch (Exception e) {
                         e.printStackTrace();
                         }
                         }
                        
                         private void setUserWithSubmittedValues() {
                         logger.debug(tempUser.getUsername()+" - "+tempUser.getAddress()+" - "+tempUser.getPhoneNo1());
                         logger.debug(username.getLocalValue()+" - "+username.getSubmittedValue()+" - "+username.getValue());
                         logger.debug(contactNo.getLocalValue()+" - "+contactNo.getSubmittedValue()+" - "+contactNo.getValue());
                         tempUser.setUsername((String)username.getSubmittedValue());
                         tempUser.setAddress((String)address.getSubmittedValue());
                         tempUser.setPhoneNo1((String)contactNo.getSubmittedValue());
                         tempUser.setMobileContact((String)mobilePhone.getSubmittedValue());
                         }
                        
                         private void setInputValuesWithUser() {
                         username.setValue((String)tempUser.getUsername());
                         address.setValue((String)tempUser.getAddress());
                         contactNo.setValue((String)tempUser.getPhoneNo1());
                         mobilePhone.setValue((String)tempUser.getMobileContact());
                         }
                        
                         //action methods...
                         public String save() {
                         //FacesContext f;f.getContext().getCurrentInstance().get
                         //setUserWithSubmittedValues();
                         logger.debug("saving.... '"+tempUser.getUsername()+"' with address: "+tempUser.getAddress());
                         logger.debug("Phone: "+tempUser.getPhoneNo1() + " Mobile: "+tempUser.getMobileContact());
                         if(tempUser.getUsername().equals("")) {
                         FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR,"username can not be empty");
                         return null;
                         }
                         logger.debug("pass:"+password + " verify:"+verifyPassword);
                         if(password.equals("") || verifyPassword.equals("") || !password.equals(verifyPassword)) {
                         FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR,"password is empty or password and verification don't match");
                         return null;
                         }
                         if(isNewUser()) {
                         saveNewUser();
                         }else {
                         updateUser();
                         }
                        
                         return null;
                         }
                        
                         public void userListValueChanged(ValueChangeEvent event) {
                        
                         try {
                         selectedUsername = (String) event.getNewValue();
                         reload = true;
                         } catch (Exception e) {
                         e.printStackTrace();
                         }
                         }
                        
                        
                        
                         public String back(){
                         return "back";
                         }
                        
                         @Remove @Destroy
                         public void destroy() {
                        
                         }
                        
                         // getters and setters....
                         public List<String> getSelectedRoles() {
                         return selectedRoles;
                         }
                        
                         public void setSelectedRoles(List<String> selectedRoles) {
                         this.selectedRoles = selectedRoles;
                         }
                        
                         public User getTempUser() {
                         if(tempUser == null) {
                         tempUser = new User();
                         }
                         return tempUser;
                         }
                        
                         public void setTempUser(User user) {
                         this.tempUser = user;
                         }
                        
                         public String getVerifyPassword() {
                         return verifyPassword;
                         }
                        
                         public void setVerifyPassword(String verify) {
                         this.verifyPassword = verify;
                         }
                        
                        
                         public HtmlSelectOneMenu getSelectOneUser() {
                         return selectOneUser;
                         }
                        
                         public void setSelectOneUser(HtmlSelectOneMenu selectOneUser) {
                         this.selectOneUser = selectOneUser;
                         }
                        
                         public SelectItem[] getAllUsers() {
                         if(allUsers == null) {
                         loadAllUsers();
                         }
                         return allUsers;
                         }
                        
                         public void setAllUsers(SelectItem[] allUsers) {
                         this.allUsers = allUsers;
                         }
                        
                         public String getSelectedUsername() {
                         return selectedUsername;
                         }
                        
                         public void setSelectedUsername(String selectedUsername) {
                         this.selectedUsername = selectedUsername;
                         }
                        
                         public SelectItem[] getAllGroups() {
                         if(allGroups == null) {
                         loadAllGroups();
                         }
                         return allGroups;
                         }
                        
                         public void setAllGroups(SelectItem[] allGroups) {
                         this.allGroups = allGroups;
                         }
                        
                         public ArrayList<SelectItem> getAllRoles() {
                         if(allRoles == null) {
                         loadAllRoles();
                         }
                         return allRoles;
                         }
                        
                         public void setAllRoles(ArrayList<SelectItem> allRoles) {
                         this.allRoles = allRoles;
                         }
                        
                         public Long getSelectedGroup() {
                         return selectedGroup;
                         }
                        
                         public void setSelectedGroup(Long selectedGroup) {
                         this.selectedGroup = selectedGroup;
                         }
                        
                         public boolean isNewUser() {
                         if(selectedUsername.equals("0")) {
                         newUser = true;
                         }else {
                         newUser = false;
                         }
                         return newUser;
                         }
                        
                         public void setNewUser(boolean newUser) {
                         this.newUser = newUser;
                         }
                        
                         public String getPassword() {
                         return password;
                         }
                        
                         public void setPassword(String password) {
                         this.password = password;
                         }
                        
                         public UIInput getAddress() {
                         return address;
                         }
                        
                         public void setAddress(UIInput address) {
                         this.address = address;
                         }
                        
                         public UIInput getContactNo() {
                         return contactNo;
                         }
                        
                         public void setContactNo(UIInput contactNo) {
                         this.contactNo = contactNo;
                         }
                        
                         public UIInput getMobilePhone() {
                         return mobilePhone;
                         }
                        
                         public void setMobilePhone(UIInput mobilePhone) {
                         this.mobilePhone = mobilePhone;
                         }
                        
                         public UIInput getUsername() {
                         return username;
                         }
                        
                         public void setUsername(UIInput username) {
                         this.username = username;
                         }
                        
                        
                         }