Amira
Amira

Reputation: 3280

Retrieving data from hashMap in web page

In my managed bean i have a hashmap :`HashMap > reqLeafData;

So for every ReqLeaf i create a list of strings to store some info :

 ReqLeaf reqLeaf=new ReqLeaf(pReqWrapper,(ReqFamily) requirement.getData());
                System.out.println(ReqWrapper.getCatString(reqLeaf.getCat()));
                testReqsList.add(reqLeaf);
                reqInfolist.add(ReqWrapper.getCatString(reqLeaf.getCat()));
                reqInfolist.add(ReqWrapper.getStateString(reqLeaf.getStateFromModel())); 
                reqInfolist.add(ReqWrapper.getComplexString(reqLeaf.getComplexeFromModel()));
                reqLeafData.put(reqLeaf,reqInfolist);

So in my ReqLeaf dataTable i want to retrieve the infos so here's the code :

<p:dataTable id="testReqDT" var="testReq" value="#{projectTestManagementMB.testReqsList}">  

                                   <p:column headerText="Id">  
                                      <h:outputText value="#{testReq.idBdd}" />  
                                   </p:column>  

                                   <p:column headerText="Name">  
                                      <h:outputText value="#{testReq.longName}"  />  
                                   </p:column>  

                                   <p:column headerText="Category">  
                                      <h:outputText value="#{projectTestManagementMB.reqLeafData(testReq)[0]}"  />  
                                   </p:column>  

`

But i get always errors because this value isn't rightly writed :

<h:outputText value="#{projectTestManagementMB.reqLeafData(testReq)[0]}"  />

reqLeafData is seen like a method and not an like attribute :

Grave: javax.el.ELException: /manageProjectTestsReqPage.xhtml @1152,119 value="#{projectTestManagementMB.reqLeafData(testReq)[0]}": Unable to find method [reqLeafData] with [1] parameters

so How to retrieve values from reqLeafData by using the ReqLeaf as key ?

Any help will be appreciated

Upvotes: 1

Views: 285

Answers (2)

dimas
dimas

Reputation: 6073

I think that problem occured because you didn't write getters and setters for your map. You should write them and then retrieve data from map using:

#{projectTestManagementMB.reqLeafData[testReq]}

To access the list item inside map you can use this:

#{(projectTestManagementMB.reqLeafData[testReq])[0]}

Last expression will fetch first item from the list.

Upvotes: 2

Amira
Amira

Reputation: 3280

here's the solution :

#{projectTestManagementMB.reqLeafData[testReq][0]}

Upvotes: 1

Related Questions