1

Basically, I have 2 collections of objects: List and List. Each person has a value in each criteria, which builds the matrix to be displayed:

                  criteria1     criteria2     criteria3     ...
      person1         2             5             8
      person2         4             3             1
      person3         6             9             0
        ...

The number of elements in each collection is unknown since they are coming from query results. My model has 3 tables: criteria, person and criteria_person (which has the personId, criteriaId and qualification).

I have been able to display the datatable with these collections but I have no clue about how to relate them to the qualification associated to them, and then make them persist. So, any guidance would be much appreciated.

aleafonso
  • 2,244
  • 8
  • 38
  • 58
  • http://stackoverflow.com/questions/16350122/primefaces-3-dimensional-datatable – xild Aug 07 '15 at 11:15
  • 1
    Not sure if the '3D' concept in the link posted by @xild is a 100% match, but the 'columns' part in it is. See also http://stackoverflow.com/questions/25658034/primefaces-static-and-dynamic-columns-in-datatable and also take a good look in the PrimeFaces showcase'. 'dynamic' number of columns is in there – Kukeltje Aug 07 '15 at 11:20
  • @Kukeltje I agree. I have started using the tag "columns" from primefaces datatable but still don´t know how to relate each qualification (cell values) to the dynamically created columns. I may be missing some conceptual details – aleafonso Aug 07 '15 at 11:22
  • I have no clue what you mean by _"but still don´t know how to relate each qualification (cell values) to the dynamically created columns"_ please clarify by e.g. adding a simplified objectmodel to the question and a simplified (but both 100% valid xhtml – Kukeltje Aug 07 '15 at 11:25

2 Answers2

-1

You just asked such a wide question. For this you can use row expansion see more

You can simple add a table with person name and criteria would be it's inner table like in the example on the showcase. here is sample example:

<p:dataTable var="person" value="#{dtBasicView.peronsViewList}">
        <f:facet name="header">
            Person with criteria
        </f:facet>
        <p:column style="width:16px">
            <p:rowToggler />
        </p:column>
        <p:column headerText="Person Name">
            <h:outputText value="#{person.personName}" />
        </p:column>
        <p:column headerText="Reg. Date">
            <h:outputText value="#{person.regDate}" />
        </p:column>

        <p:rowExpansion>
            <p:panelGrid  columns="2" columnClasses="label,value" style="width:300px">
               <p:dataTable var="cri" value="#{person.criteria}">
                    <p:column headerText="Id">
                        <h:outputText value="#{cri.id}" />
                    </p:column>

                    <p:column headerText="Year">
                        <h:outputText value="#{cri.year}" />
                    </p:column>

                    <p:column headerText="Brand">
                        <h:outputText value="#{cri.brand}" />
                    </p:column>

                    <p:column headerText="Color">
                        <h:outputText value="#{cri.color}" />
                    </p:column>
                </p:dataTable>
            </p:panelGrid>
        </p:rowExpansion>
    </p:dataTable>
Sarz
  • 1,970
  • 4
  • 23
  • 43
  • 1
    Mmm thanks but "The number of elements in each collection is unknown". Which means that columns should be created dynamically – aleafonso Aug 07 '15 at 11:17
  • thanks but I do need a plain datatable as described in the example – aleafonso Aug 07 '15 at 11:20
  • @Sarz. please ask questions in a comment instead of 'guessing' in answers. – Kukeltje Aug 07 '15 at 11:21
  • @Kukeltje thanks, I believe primefaces is such a wide library. For this scenario I am suggesting him something with rough example ( for an idea ) – Sarz Aug 07 '15 at 11:27
  • @aleafonso why don't you explore primefaces little more. You will see what you need – Sarz Aug 07 '15 at 11:29
  • @Sarz: suggestions can be answers if you fully understand what someone wants/needs. And no offence, but you missed the 'needs' The second one being not to clear, but the first one was obvious. But regarding the exploring you are right (but that is again a comment). The dynamic columns could have been seen in the showcase then – Kukeltje Aug 07 '15 at 11:32
-1

I am not sure if I understood the question 100%, but I solved something similar with p:columns and a backing bean method which resolves the value for the current cell:

<p:dataTable value="#{curSearch.getSearchResults()}" var="curSearchResult">
    <p:columns value="#{curSearch.determineItems()}" var="curSearchItem">

        <f:facet name="header">
            <h:outputText value="#{curSearchItem}" />
        </f:facet>

        <h:outputText value="#{someUiBusinessLogicBean.generatePropertyValue(curSearchResult, curSearchItem)}" />
    </p:columns>
</p:dataTable>

Hope this shows the idea. But I would recommend to build a handy UI model.

opfau
  • 731
  • 9
  • 37
  • This indeed comes close to what I think is needed to But since I do not see any thing repeating in cells, I'd say that you could also (should?) do the 'generatePropertyValue' upfront in the columns model. The 'virtual' getter here could be called many times and since you should not do (heavy) work in getters, doing it upfront in is better. But that just means to populate the view model correctly – Kukeltje Aug 07 '15 at 13:41