1 Reply Latest reply on Jun 27, 2012 6:17 AM by Brendan Healey

    How to display hashmap object values in user interface??

    Smitha Dsouza Newbie

      I have following code in my Bean

      Map<BigDecimal, String> hotelFeaturesMap = new HashMap<BigDecimal, String>();

      hotelFeaturesMap.put(BigDecimal.valueOf(attribute.getId().longValue()),

                                           attribute.getLabel().getContent());

       

      in my .xhtml am trying to get all the values that is there in hotelFeaturesMap..

      how do i do it??

       

      i tried below way but it is showing both key and value but i want to show only the values....

       

      <span><h:outputText value="Hotel Facilities" /></span>

       

          <rich:dataList value="#{hotelReviewBean.selectedAccommodation.staticAccommodationVO.hotelFeaturesMap}" var="features"  rows="5" type="disc" title="Hotel Features">

                     <h:outputText value="#{features}"

                              width="84px" height="82px" />

            </rich:dataList>

       

      Can any body guide me... what way i can get oly the values...

        • 1. Re: How to display hashmap object values in user interface??
          Brendan Healey Master

          I think that the richfaces data iteration components take the same types for the value attribute as h:datatable, which

          are:

           

          • A java object
          • An array
          • A List
          • A java.sql.ResultSet
          • A javax.faces.model.DataModel

           

          In reality people almost always use lists and datamodels (for lazy loading). The easiest thing to do is to

          convert your map values into a list like this:

           

          List<String> list = new ArrayList<String>(hotelFeaturesMap.values());

           

          An alternative solution is to write your own EL function, but the above is the easiest thing for you.

           

          Regards,

          Brendan.

          1 of 1 people found this helpful