9 Replies Latest reply on Feb 26, 2008 1:53 PM by pmuir

    Problem with OneSelectMenu and entity selection

    amitdk

      I am trying to figure out what I'm doing wrong conceptually with the following piece of code:



      <h:selectOneMenu id="objectiveTask" value="#{taskAssignmentHome.instance.objectiveTask}" required="true">

      <s:selectItems id="objtsklst" value="#{objectiveTaskList}" var="objtask" label="#{objtask.description}" noSelectionLabel="Select..." hideNoSelectionLabel="true" />
      <s:convertEntity />
      </h:selectOneMenu>


      TaskAssignment (Entity) has a many-to-one relationship with ObjectiveTask (Entity). I would imagine that selectOneMenu should be able to set objectiveTask on taskassignment. However, it never does. Am I missing something here - shouldn't I be able to do this?


      I have another way around by adding a convertor and then setting objectiveTask. But that doesn't seem natural.
      Please provide any insight as to why this shouldn't be possible. I am using Seam 1.2.1


      Thanks
      Amit

        • 1. Re: Problem with OneSelectMenu and entity selection
          amitdk

          Still no luck with this. I have pretty much done exactly the same thing as documented here -
          SeamEntityConverter


          Only change I see here is in selectItems, instead of just value="#{objectiveTaskList}", I changed it to value="#{objectiveTaskList.resultList}". However instead of declaring the select item list component in the components.xml, I am using the generated annotated ObjectiveTaskList.


          Please any help with this would be appreciated. Since the article also seems to point that what I am doing is legit, I really would like someone to point out what I am missing.


          Thanks
          Amit


          • 2. Re: Problem with OneSelectMenu and entity selection

            Hi!
            How do you know it is not working?
            It just silently fails?
            It throws an exception?


            Are modifing one of the seam-gen CRUD editor pages? or is it a page created from scratch by you? how do you know that the problem is the OneSelectMenu and not the code you use to persist your POJO?


            Regards
            LuxSpes

            • 3. Re: Problem with OneSelectMenu and entity selection
              damianharvey.damianharvey.gmail.com

              Show your code for ObjectiveTaskList. Is the list a list of SelectItems (if so you should use f:selectItems) or a list of entities?


              Cheers,


              Damian.


              • 4. Re: Problem with OneSelectMenu and entity selection
                nickarls

                Place a h:messages tag on the page and see if you get any value not in list-errors. If so, override hashCode() and equals() on the entity...

                • 5. Re: Problem with OneSelectMenu and entity selection
                  amitdk

                  Thanks for all the responses. Here's more information as requested.


                  I am not using the seam-gen CRUD page for this. However the domain objects are seam-gen generated. Here's what ObjectiveTaskList looks like:



                  @Name("objectiveTaskList")
                  public class ObjectiveTaskList extends EntityQuery {
                  
                       private static final String[] RESTRICTIONS = {"lower(objectiveTask.description) like concat(lower(#{objectiveTaskList.objectiveTask.description}),'%')",};
                  
                       private ObjectiveTask objectiveTask = new ObjectiveTask();
                  
                       @Override
                       public String getEjbql() {
                            return "select objectiveTask from ObjectiveTask objectiveTask";
                       }
                  
                       @Override
                       public Integer getMaxResults() {
                            return 25;
                       }
                  
                       public ObjectiveTask getObjectiveTask() {
                            return objectiveTask;
                       }
                  
                       @Override
                       public List<String> getRestrictions() {
                            return Arrays.asList(RESTRICTIONS);
                       }
                  
                  }
                  


                  And here's the TaskAssignmentHome that was generated:



                  @Name("taskAssignmentHome")
                  public class TaskAssignmentHome extends EntityHome<TaskAssignment> {
                  
                       @In(create = true)
                       ObjectiveTaskHome objectiveTaskHome;
                       @In(create = true)
                       AssociateHome associateHome;
                  
                       public void setTaskAssignmentId(Integer id) {
                            setId(id);
                       }
                  
                       public Integer getTaskAssignmentId() {
                            return (Integer) getId();
                       }
                  
                       @Override
                       protected TaskAssignment createInstance() {
                            TaskAssignment taskAssignment = new TaskAssignment();
                            return taskAssignment;
                       }
                  
                       public void wire() {
                            ObjectiveTask objectiveTask = objectiveTaskHome.getDefinedInstance();
                            if (objectiveTask != null) {
                                 getInstance().setObjectiveTask(objectiveTask);
                            }
                            Associate associate = associateHome.getDefinedInstance();
                            if (associate != null) {
                                 getInstance().setAssociate(associate);
                            }
                       }
                  
                       public boolean isWired() {
                            if (getInstance().getObjectiveTask() == null)
                                 return false;
                            if (getInstance().getAssociate() == null)
                                 return false;
                            return true;
                       }
                  
                       public TaskAssignment getDefinedInstance() {
                            return isIdDefined() ? getInstance() : null;
                       }
                  
                  }
                  


                  My seam page does have a page.xml file but the following is all it contains:


                  <page no-conversation-view-id="/StatusReport.xhtml" 
                                 login-required="true">
                     
                     <begin-conversation join="true"/>
                     
                     <action execute="#{taskAssignmentHome.wire}"/>
                        
                     <navigation from-action="#{taskAssignmentHome.update}">
                         <end-conversation/>
                         <redirect view-id="/StatusReport.xhtml"/>
                     </navigation>
                     
                     <navigation from-action="#{taskAssignmentHome.remove}">
                         <end-conversation/>
                         <redirect view-id="/StatusReport.xhtml"/>       
                     </navigation>
                       
                     <navigation from-action="#{taskAssignmentHome.persist}">
                         <end-conversation/>
                         <redirect view-id="/StatusReport.xhtml"/>
                     </navigation>
                          
                  </page>
                  



                  For some reason, the code never invokes the setObjectiveTask on TaskAssignment, though its doing a get on it. Also, the <h:message/> shows that value is required, meaning objectiveTask was not set on TaskAssignment.


                  Thanks
                  Amit

                  • 6. Re: Problem with OneSelectMenu and entity selection
                    franciscoperedo

                    Hi!
                    Please, if you  can post the code of StatusReport.xhtml
                    Regards,
                    LuxSpes

                    • 7. Re: Problem with OneSelectMenu and entity selection
                      amitdk

                      Here's the part that submits to the TaskEdit.xhtml


                      <s:button view="/TaskEdit.xhtml" value="Add a Task">
                          <f:param name="associateId" value="#{user.associate.id}"/>
                      </s:button>
                      



                      Also, I posted the wrong page.xml - here's the correct one.


                      <page no-conversation-view-id="/StatusReport.xhtml" 
                                     login-required="true">
                         
                         <begin-conversation join="true"/>
                         <param name="associateId" value="#{associateHome.associateId}"/>
                         
                         <action execute="#{taskAssignmentHome.wire}"/>
                            
                         <navigation from-action="#{taskAssignmentHome.update}">
                             <end-conversation/>
                             <redirect view-id="/StatusReport.xhtml"/>
                         </navigation>
                         
                         <navigation from-action="#{taskAssignmentHome.remove}">
                             <end-conversation/>
                             <redirect view-id="/StatusReport.xhtml"/>       
                         </navigation>
                           
                         <navigation from-action="#{taskAssignmentHome.persist}">
                             <end-conversation/>
                             <redirect view-id="/StatusReport.xhtml"/>
                         </navigation>
                              
                      </page>
                      



                      Could it be scope that is causing an issue here? I tried adding Scope(CONVERSATION) on taskAssignmentHome, and I also tried adding it to TaskAssignment (running out of ideas here ..:(), but with no luck.


                      - Amit


                      • 8. Re: Problem with OneSelectMenu and entity selection
                        amitdk

                        For whatever reason, looks like there wasn't anything wrong with my code. The same code works perfectly in Firefox, but does not work with IE 6.0. That's really strange....and this must surely be a bug with the SEAM code or maybe RichFaces.


                        - Amit

                        • 9. Re: Problem with OneSelectMenu and entity selection
                          pmuir

                          This should work, and as you say, it works in Firefox. If you manage to find the problem, file a JIRA so we can fix it :-)