1 Reply Latest reply on Aug 6, 2007 7:07 AM by pmuir

    convertEntity: mixing session and conversation data

    awheeler

      I am using Seam 1.2.1GA and I have problem with s:convertEntity such as:


       <h:selectOneMenu id="clientBranch" value="#{loggedInUser.clientBranch}" styleClass="input-field" required="true" style="width:50%">
       <s:selectItems value="#{editVehicleIncident.userBranchList}" var="b" label="#{b.companyName}" noSelectionLabel="[Select your company branch]" hideNoSelectionLabel="true"/>
       <s:convertEntity/>
       </h:selectOneMenu>
      


      The bean loggedInUser is a session bean. When the form submits JSF reports that the field is not valid. I have debugged the EntityConverter class and it returns the selected value correctly from the getAsObject function. This means (I assume) the validation error is occuring within JSF, in my case MyFaces.

      The session bean function is:
       public List<Company> getBranchList() {
       return this.flattenedBranches;
       }
      



      To experiment I sourced the list from a bean in the current conversation. This function gets the list from the session bean and merges it (using entityManager) into a local list.

       @In(value="loggedInUser", required=true)
       private IUser user;
      
       private List<Company> userBranchList;
       public List<Company> getUserBranchList() {
       if (this.userBranchList == null) {
       this.userBranchList = new ArrayList<Company>();
       Iterator itr = this.loggedInUser.getBranchList().iterator();
       while (itr.hasNext()) {
       Company branch = (Company)itr.next();
      
       this.userBranchList.add(super.getEntityManager().merge(branch));
       }
       }
      
       return this.userBranchList;
       }
      


      This works without JSF reporting any validation problems.

      I really don't understand why this does not work for session data as the EntityConverter class uses entityManager.find to look-up the data using the data's primary key. This means that the EntityConverter is returning a "merged" result using the current conversation's entityManager.

      Does anyone have any thoughts?

        • 1. Re: convertEntity: mixing session and conversation data
          pmuir

          JSF imposes a validation constraint on all selectXXX that the selected object *must* be in the original list. In this case you are getting the list from the session (some old (SM)PC) and the selection from the conversation (current SMPC) which, due to PC caching, are different objects.