Nested datatable in JSF 2.0

后端 未结 2 1839
春和景丽
春和景丽 2021-01-13 18:36

I am trying to fetch the questions and the associated answers. I am able to get the questions fine but the nested datatable does not even recognize the properties each answe

相关标签:
2条回答
  • 2021-01-13 18:48

    You need to put columns inside a <h:column>.

    <h:dataTable value="#{questionBacking.recentlyAskedQuestions}" var="question" rendered="#{not empty questionBacking.recentlyAskedQuestions}">
        <h:column>
            <h:outputText  value="#{question.questionTitle}" />
            <br/>
            <h:outputText  value="#{question.questionBody}" />
        </h:column>
        <h:column>
            <h:dataTable value="#{question.answers}" var="answer">
                <h:column>
                    <h:outputText  value="#{answer.answer}" />
                </h:column>
            </h:dataTable>
        </h:column>
    </h:dataTable>
    

    (note that I changed the rendered and the var attributes to be a bit more self-documenting, you might want to rename questionTitle, questionBody and answer to title, body and body respectively as well so that you don't keep duplicating the meaning)

    0 讨论(0)
  • 2021-01-13 19:00

    You can do the same thing mentioned in BalusC's answer using PrimeFaces as well. Just replace <h:dataTable> with <p:dataTable> and the same goes for column tags as well. You can create nested datatable with PrimeFaces. I recommend people to use PrimeFaces as it reduces the amount of time people spend on writing/modifying css definitions.

    0 讨论(0)
提交回复
热议问题