10 Replies Latest reply on Jul 10, 2015 3:04 AM by Nandhu TV

    Display HashMap values on Table

    Nandhu TV

      Hi All,

       

      I have an HashMap in my bean. I want to display the HashMap values in a table(UI).

      I couldn't get the key and value of the HashMap.

       

       

          hashmap.png

       

      moduleNameVersion - is the name of my HashMap in Bean.

      The #{row.key} #{row.value} is not fetching the key and value. It is just null.

      plz advise me of what should I give in the value column to get the key and value of HashMap.

      Reference would be helpful.

       

      Thank a lot

      Regards,

      Nandhu.

        • 1. Re: Display HashMap values on Table
          Ruben Rodriguez

          Hello,

           

          You do it like this:

           

              --- page ---

           

                      <af:table var="row" rowBandingInterval="0" id="t1" value="#{backingBeanScope.testBean.mapKeys}">

                          <af:iterator value="#{backingBeanScope.testBean.mapTable}" var="var">

                              <af:column sortable="false" headerText="aaa" id="c1">

                                  <af:outputText value="#{var[row]}" id="ot2"/>

                              </af:column>

                              <af:column sortable="false" headerText="aaa" id="c2">

                                  <af:outputText value="#{row}" id="ot3"/>

                              </af:column>

                          </af:iterator>

                      </af:table>

           

           

              --- Bean ---

           

              private Map<String, String> mapTable;

              private Object[] mapKeys;

           

              public Map<String, String> getMapTable() {

                  mapTable = new HashMap<String, String>();

                  mapTable.put("1", "val1");

                  mapTable.put("2", "val2");

                  mapTable.put("3", "val3");

                  return mapTable;

              }

            

              public Object[] getMapKeys() {

                  return getMapTable().keySet().toArray();

              }

           

          regards,

          Ruben

          • 2. Re: Display HashMap values on Table
            Jagadeesh Badri

            Hi

             

            As hashMap is instance variable in your Bean, generate datacontrol to your bean and drag and drop the hashMap as table.

            • 3. Re: Display HashMap values on Table
              Ashish Awasthi
              1 person found this helpful
              • 4. Re: Display HashMap values on Table
                Nandhu TV

                Hi Ruben,

                Thanks a lot. your example worked fine.

                Now I want to display the values of HashMap<String, HashMap<BigInteger, String>> in a table.

                I tried to achieve it using your HashMap<String, String> example but I couldn't get the answer.

                Plz help me out.

                 

                Regards,

                Nandhu.

                • 5. Re: Display HashMap values on Table
                  Ruben Rodriguez

                  Hello,

                   

                  What do you want to achieve? Please tell us what output do you expect.

                  I will try look at it this afternoon.

                   

                  regards,

                  Ruben

                  • 6. Re: Display HashMap values on Table
                    Nandhu TV

                    Hi Ruben,

                     

                    I have a HashMap<String, HashMap<BigInteger, String>> HashMap in my bean.

                    I want to display the HashMap values in an af:Table

                     

                    I have a HashMap with 3 values

                    1. String - ModuleName

                    2. BigInteger - RuleId

                    3. String - Version

                    HashMap<String, HashMap<BigInteger, String>> getRulebaseValues = new HashMap<String, HashMap<BigInteger, String>>();

                     

                    private Object[] ruleHashMapValues;      

                    public Object[] getHashmapValues() {

                        return moduleNameVersion.keySet().toArray();

                    }

                    // using this ruleHashMapValues Object I can get the ModuleName(key of the Hashmap) to be displayed in the table

                     

                    This my output now

                        Untitled.png1.png

                     

                    What should I give in the value field to display Version and RuleId

                     

                    <af:table var="row" rowBandingInterval="0" id="t2" value="#{pageFlowScope.MyBean.ruleHashMapValues}">

                         <af:iterator var="var" value="#{pageFlowScope.MyBean.getRulebaseValues}">

                              <af:column sortable="false" headerText="Module" id="c6">

                                      <af:outputText value="#{row}" id="ot3"/>

                                </af:column>

                                <af:column sortable="false" headerText="Version" id="c7">

                                      <af:outputText value=" " id="ot4"/>

                                 </af:column>

                                 <af:column sortable="false" headerText="RuleId" id="c8">

                                    <af:outputText value=" " id="ot5"/>

                                </af:column>

                         </af:iterator>

                    </af:table>  

                     

                     

                    Thank you,

                    Regards,

                    Nandhu.

                    • 7. Re: Display HashMap values on Table
                      Ruben Rodriguez

                      Hello,

                       

                      Why do u use a HashMap inside a HashMap instead of using a List of Module objects.

                       

                      regards,

                      Ruben.

                      • 8. Re: Display HashMap values on Table
                        Nandhu TV

                        Hi,

                         

                        Like you said I converted my HashMap to HashMap<String, ArrayList<arraylist>>

                        My ArrayList<arraylist> is having two values BigInteger - RuleId & String - Version and HashMap(String) is having String - ModuleName

                        plz hep me out to display the 3 values in an af:Table in UI


                        Thanks and Regards,

                        Nandhu

                        • 9. Re: Display HashMap values on Table
                          Ruben Rodriguez

                          Hello,

                           

                          This is what i ment:

                           

                          module class:

                           

                          public class Module{

                            String name;

                            BigInteger ruleId;

                            String version;

                           

                          //Constructor

                          //get and set methods

                          }

                           

                           

                          bean:

                           

                           

                          private List<Module> moduleList;

                           

                          public List<Module> getModuleList(){

                          //build your list here...

                          moduleList = new ArrayList<Module>();

                          moduleList.add(new Module("Module1", 1, "Version1"));

                          .....

                          .....

                            return moduleList;

                          }

                           

                           

                          page:

                           

                           

                          <af:table value="myBean.moduleList" var="row" .....>

                              <af:column>

                                 <af:outputText value="#row.module}">

                              </af:column>

                              <af:column>

                                 <af:outputText value="#{row.version}">

                              </af:column>

                              <af:column>

                                 <af:outputText value="<#{row.ruleId}">

                              </af:column>

                          </af:table>

                           

                           

                          regards,

                          Ruben.

                          1 person found this helpful
                          • 10. Re: Display HashMap values on Table
                            Nandhu TV

                            Hi Ruben,

                             

                            Thanks a lot. I tried your suggestion, it worked.

                            Regards,

                            Nandhu