AlexandruMN
AlexandruMN

Reputation: 63

Combining two dataTables based on commonalities JSF

I have the following database structure: a Project that has multiple sub-projects and multiple users that have booked some time on a specific sub-project. I need to display for each project the list of sub-projects and for each sub-project the users working on it and the total time booked. Like this:

Project1
   Subproject1       User1   TimeBooked
                     User2   TimeBooked 

   Subproject2       User3   TimeBooked 
                     User2   TimeBooked

This is what I have so far:

<p:dataTable var="subproj"
             value="#{project_stats_user_chart.selectedProject.subprojects}"
             id="projectSubprojects">

    <p:column>
        <h:outputText value="#{subproj.type}" style="font-size: 1em;"></h:outputText>
    </p:column>

    <p:column>
        <p:dataTable var="user"
                     value="#{project_stats_user_chart.users}" 
                     id="SubprojectsUsers">

            <p:column>
                <h:outputText value="#{user.firstName}"
                              style="font-size: 1em;"></h:outputText>
                <h:outputText value="#{user.lastName}" style="font-size: 1em;">
                </h:outputText>
            </p:column>
        </p:dataTable>
    </p:column>
</p:dataTable>

My problem now is displaying the booked time as needed. I have a query calculating the sum on each sub-project per user but I need somehow to iterate over these two tables based on their commonalities or merge the two tables so I can get the combination I want. I am new to PrimeFaces so perhaps somebody could help me with this

Upvotes: 0

Views: 1467

Answers (1)

BalusC
BalusC

Reputation: 1108802

Do it in Java (model) side, not in XHTML (view) side. You should in Java side prepare exactly the model the view expects. The view should be kept as dumb as possible and just present the model it was given to.

Upvotes: 2

Related Questions