4 Replies Latest reply on Dec 15, 2010 7:51 AM by Thando Madida

    Empty dropdown list

    Thando Madida Newbie
      Hi,

      Hoping someone will be able to assist.
      I'm not sure if I'm missing something, my dropdown list is empty, although if I use h:outputText the course name do display.

      Any help will be much appreciated.

      Here's a snippet of both my bean and jsf.
      Bean
      ----
      @Begin(join=true)
      public ArrayList<HashMap<String, Object>> getCourseList() throws Exception
      {
        Integration ig = (Integration)Component.getInstance("integration");
        if (ig != null)
        {
          HashMap localHashMap;
          ArrayList resList = ig.getList("CourseDetails", "select ed from CourseDetails ed");
          System.out.println("The length of the List is " + resList.size() + " Elements");
          for (Iterator localIterator = resList.iterator(); localIterator.hasNext(); localHashMap = (HashMap)localIterator.next());
            
          return resList;
        }
        else
        {
          System.out.println("!Unable to get integration component!");
        }
        return null;
      }

      jsf
      ---

      <h:selectOneMenu value="#{studentHome.instance.fkCourseDetails}">

        <a4j:repeat id="courseList" value="#{studentList.courseList}" var="course">

          <f:selectItems itemValue="#{course.get('fkCourse')}" itemLabel="#course.get('courseName')}" />
        </a4j:repeat>                     

      </h:selectOneMenu>

      Thanking you in advance
      Thandos

        • 1. Re: Empty dropdown list
          Christoph Kraus Newbie

          Hi Thandos,


          I think something like this should work...




          <a4j:repeat id="courseList" value="#{studentList.courseList}" var="course">
              <f:selectItem itemLabel="#{course.getKey()}" itemValue="#{course.getValue()}"/>
          </a4j:repeat>



          Iterating through a HashMap returns objects of the type

          java.util.Map.Entry<K, V>



          Best regards,
          Chris


          • 2. Re: Empty dropdown list
            Thando Madida Newbie

            Thank you Chris for your response.


            I tried what you suggested, but to no avail.


            Honestly don't know if i'm doing something wrong.


            Funny thing is if I move a4j:repeat outside h:selectOneMenu, then i get multiple dropdown lists and each showing individual courseNames


            Thanking you in advance
            Thandos

            • 3. Re: Empty dropdown list
              Martin Frey Newbie

              Hi Thandos
              Can you not use the f:items tag and call a function which returns you a list of select items? I've always used this approach to have dynamic select values. If you work directly with entities i use normally the s:items tag.


              Something like this:



              <h:selectOneMenu id="selectValue" value="#{action.type}">
                   <f:selectItems value="#{actionTypeListItems}" />
              </h:selectOneMenu> 




                    /**
                    * Gets the action type list items.
                    * 
                    * @return the action type list items
                    */
                   @Factory(value = "actionTypeListItems", scope = ScopeType.APPLICATION)
                   public List<SelectItem> getActionTypeListItems() {
                        List<SelectItem> result = new ArrayList<SelectItem>();
                        result.add(new SelectItem(null, "Select an action type"));
                        result.add(new SelectItem(ActionType.CORRECTIVE));
                        result.add(new SelectItem(ActionType.PREVENTIVE));
                        return result;
                   }
              




              • 4. Re: Empty dropdown list
                Thando Madida Newbie

                Hi Martin


                I also tried returnig SelectItem, but it still made no change.


                Just to add on...


                I have two databases


                Course (entity CourseDetails, fields - pkCourse, courseName)and
                Student (entity StudentDetails, fields - pkStudent, studentName, fkCourse),entities where generated using seam-gen.


                export both course and student as two separate war files. I've managed to get them to communicate with each other through services and ESB.
                Now in student jsf I've created a dropdown for fkCourse to display courseNames, but in my case it shows nothing.


                Hope it's a bit clear as to what I'm trying to do.


                If there is an alternative workaround to what I'm trying to achieve, it will be appreciated.


                Thanking you in advance
                Thandos