简体   繁体   中英

Filling columns with the right data in subTable doesn't work (JSF, Primefaces)

I have this code below:

<h:panelGrid id="formDatatable">
            <p:dataTable var="Resource" value="#{resource.listResourceForDataTable}">  
                <p:subTable var="access" value="#{resource.listResourceForSubTable}">
                    <f:facet name="header">
                        #{Resource.firstname} #{Resource.lastName}
                    </f:facet>
                    <p:column> 
                        #{access.skillLevel}
                    </p:column> 
                    <p:column>  
                        #{access.skillName}
                    </p:column>

                </p:subTable>
            </p:dataTable>  
        </h:panelGrid>

In value of the DataTable: a list of Resource (complex object with Strings and Map)

In value of the SubTable: a list of Resource with just 2 fields: ---> skillLevel (String) and skillName (String).

The result is (level of the skill/ name of the skill):

http://www.gilawhost.com/images/dywyipz9.png

As you can see it fills the "Headers" with all elements in the list of my SubTable. It's not that i want, because "albert first" (Resource) has learnt java (Skill) and has 2 in levelOfSkill. He hasnt the others skills.

I want to have in my table:

albert first: 2 - java

mickael jackson: 2 - jee ; 3 - php

Tom Hawks : 2 - php ; 4 - java

But i have all the skills each time in each Header. How can i "separate" the data? I thought DataTable and SubTable would do this job.

Found. I had to "convert" my map into a List:

public List<Map.Entry<Skill, Niveau>> getSkillNiveauMap() {
    Set<Map.Entry<Skill, Niveau>> map = skillLevel.entrySet();        
    return new ArrayList<Map.Entry<Skill, Niveau>>(map);        
}

Afterwards, i call the entries i need:

<p:dataTable id="resources" var="Resource" value="#{resource.listOfAllResources}">                  

                <p:subTable var="skill" value="#{Resource.skillNiveauMap}">  
                    <f:facet name="header">  
                        #{Resource.firstname}  #{Resource.lastName}   
                    </f:facet>

                    <p:column>
                        #{skill.key.title} 

                    </p:column>

                    <p:column>
                        #{skill.value.niveau}

                    </p:column>

                </p:subTable>

            </p:dataTable> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM