1 Reply Latest reply on Jan 30, 2011 3:47 AM by armahdi

    SelectOneMenu and HashMap

    xstyle

      Hey guys,


      I'm working on a project and I've got a problem with a HashMap and SelectOneMenu.


      The problem concerns several entities, let's call them Group, Topic and Supervisor and a session bean called GroupMapping


      In Group I have:


      ...
      private List<Topic> topics;
      private Map<Topic, Supervisor> topicsToSupervisors;
      ...
      
      + getters and setters



      Supervisor:


      ...
         private List<Topic> topics;
         private List<Group> groups;
      ... 
      
      + getters and setters



      The Topic has just an id and name.


      The idea is there can be only one supervisor for each of the group's topics. There are some beans that check whether or not




      <s:decorate id="groupSupervisorMapDecorate" template="edit.xhtml">
           <ui:repeat id="groupTopics" value="#{group.topics}" var="t">
                <h:selectOneMenu value="#{group.topicsToSupervisors}" required="true">
                     <s:selectItems value="#{groupMapping.supervisesTopic(t)}" var="s" label="#{s.value.name}" noSelectionLabel="#{messages.pleaseSelect}"/>
                </h:selectOneMenu>
                <br />
           </ui:repeat>
      </s:decorate>
      



      GroupMapping:


      ...
      public List<Map.Entry<Topic, Supervisor>> supervisesTopic(Topic topic) {
         List<Supervisor> all = em.createQuery("from Supervisor s").getResultList();
         Map<Topic, Supervisor> entries = new HashMap<Topic, Supervisor>();
         List<Map.Entry<Topic, Supervisor>> results = new ArrayList<Map.Entry<Topic, Supervisor>>();
         for (Supervisor s: all) {
            for(Topic t: s.getTopics()) {
               if(t.getName().equals(topic.getName())) {
                  entries.put(s, t);
               }
            }
         }
         for(Map.Entry<Topic, Supervisor> e: entries.entrySet()) {
            results.add(e);
         }
         
         return results;
      }
      ...
      



      What I'm trying to do is select the supervisor for each of the topics the group has. The code seems to be working but it doesn't update the Map in Group. The console only shows hibernate doing some selects from the database but no inserting or anything. Tell me if you need to see anything else.


      I'm still pretty new to Seam and Java overall so any help would be appreciated! Thanks in advance! :)