4 Replies Latest reply on Aug 6, 2009 5:52 AM by Nick Belaevski

    Render dataTable via a hashMap

    Neerou b Newbie

      Is it possible to render a hashMap via a datatable?

      Thanx
      Neerou

        • 1. Re: Render dataTable via a hashMap
          Neerou b Newbie

          Any idea on the above?

          • 2. Re: Render dataTable via a hashMap
            Neerou b Newbie

            How would i access a list of classes from a hashmap to render the list into columns?

            Structure of the hashmap: Map<String,List< LmsLeavesRequests>> leavesRequestPerEmployee

            the lst has to be rendered into the dataTable control. How could the class be accessed along with its attributes?

            With thanx
            Neerou

            • 3. Render a list having various items in a list
              Neerou b Newbie

               

              <rich:dataTable id="requestTable" border="0" var="requests"
               rendered="#{not empty leavesRequestPerEmployee}"
               value="#{leavesRequestPerEmployee}">
               <h:column>
               <h:outputText value="#{requests.key}" />
               </h:column>
              
               <rich:dataTable value="requests.value" var="values">
               <h:column>
               <h:outputText value="#{values.lvrReason}" />
               </h:column>
               </rich:dataTable>
               </rich:dataTable>


              @DataModel
               private Map<String,List< LmsLeavesRequests>> leavesRequestPerEmployee;



              @SuppressWarnings("unchecked")
               @Factory("leavesRequestPerEmployee")
               public void findRequests(){
               try{
               Query query = entityManager
               .createQuery("select lmsLeavesRequests from LmsLeavesRequests lmsLeavesRequests");
              
               List<LmsLeavesRequests> listRequests=query.getResultList();
               leavesRequestPerEmployee = new LinkedHashMap<String, List<LmsLeavesRequests>>();
              
               for (LmsLeavesRequests lmsLeavesRequests :listRequests ) {
               String usrLogin = lmsLeavesRequests.getLmsUsersByLvsUsrId().getUsrLogin();
               if(leavesRequestPerEmployee != null && leavesRequestPerEmployee.containsKey(usrLogin)){
               //append requests
               //leavesRequestPerEmployee.put(lmsLeavesRequests.getLmsUsersByLvsUsrId().getUsrLogin(), lmsLeavesRequests.getLmsLeaves());
               List<LmsLeavesRequests> requestlst = new ArrayList<LmsLeavesRequests>();
               requestlst.add(lmsLeavesRequests);
               List <LmsLeavesRequests> listToBeAppended = leavesRequestPerEmployee.get(usrLogin);
               listToBeAppended.add(lmsLeavesRequests);
               leavesRequestPerEmployee.put(usrLogin,listToBeAppended);
              
               }else{
               //create new hash key and value
              
               List<LmsLeavesRequests> requestlst = new ArrayList<LmsLeavesRequests>();
               requestlst.add(lmsLeavesRequests);
               leavesRequestPerEmployee.put(usrLogin,requestlst);
               }
               }
               }catch(Exception e){
               e.printStackTrace();
               e.getMessage();
               }
               }


              The list "requestlst" value of hashmap, can contain different objects of the LeaveRequest object. how is it possible to render all items of the list.



              • 4. Re: Render dataTable via a hashMap
                Nick Belaevski Master

                Hi,

                You can use

                value="#{leavesRequestPerEmployee['className']}"
                to render some class