Datatable column row with more than one attribute

Asked

Viewed 248 times

2

I have a Datatable with several columns. One of them is a column that should display more than one attribute in each row of that column, as it is part of a Manytomany relationship. This column will receive attributes from a List. I want to know how to display more than one attribute in the rows in that column

The datatable with the column

<p:dataTable id="monografiasDataTable" widgetVar="monografiaTable"
                value="#{gestaoMonografiasBean.listaMonografias}" var="monografia"
                emptyMessage="Nenhuma informação a ser exibida" paginator="true"
                rows="10" paginatorPosition="bottom" selectionMode="single"
                selection="#{gestaoMonografiasBean.monografia}"
                rowKey="#{monografia.id}" >

                <p:ajax event="rowSelect" update="frm:toolbar" />

                <p:ajax event="rowUnselect" update="frm:toolbar" />

            <p:column filterBy="#{monografia.listaLinhaPesquisas[0].nome}" headerText="Linha de Pesquisa">
                <f:facet name="filter" >
                    <p:selectCheckboxMenu  value="#{gestaoMonografiasBean.listaMonografiasFiltradas}" label="Selecione" onchange="PF('monografiaTable').filter()"
                        converter="omnifaces.SelectItemsConverter"> 
                        <f:selectItems
                            value="#{gestaoMonografiasBean.listaLinhaPesquisas}"
                            var="listaLinhaPesquisas"
                            itemLabel="#{listaLinhaPesquisas.nome}"
                            itemValue="#{listaLinhaPesquisas}"/>
                    </p:selectCheckboxMenu>
                </f:facet>
                <h:outputText value="#{monografia.listaLinhaPesquisas[0].nome}" />

            </p:column> 

2 answers

1


A datatable column will show as many things as are placed in your statement. Assuming you want to use a second index of the array shown would do the following:

<p:column filterBy="#{monografia.listaLinhaPesquisas[0].nome}" headerText="Linha de Pesquisa">
    <f:facet name="filter" >
        <p:selectCheckboxMenu  value="#{gestaoMonografiasBean.listaMonografiasFiltradas}" label="Selecione" onchange="PF('monografiaTable').filter()"
                        converter="omnifaces.SelectItemsConverter"> 
               <f:selectItems
                            value="#{gestaoMonografiasBean.listaLinhaPesquisas}"
                            var="listaLinhaPesquisas"
                            itemLabel="#{listaLinhaPesquisas.nome}"
                            itemValue="#{listaLinhaPesquisas}"/>
                </p:selectCheckboxMenu>
    </f:facet>
    <h:outputText value="#{monografia.listaLinhaPesquisas[0].nome}" /> 
    <br/>
    <h:outputText value="#{monografia.listaLinhaPesquisas[1].nome}" />    
</p:column> 

I added this excerpt here:

<br/>
<h:outputText value="#{monografia.listaLinhaPesquisas[1].nome}" /> 
  • Thanks for the help. But as I leave to show dynamically, as this column can receive both an attribute and several

  • 1

    In this case you can do the following: 1 - Build a String that has all the names you want to display when you are in read mode 2 - Use something like a Selectmanymenu with the items already selected when you are in edit mode.

  • You made me open my head to something else I had researched and hadn’t been able to apply, which was Datalist. I used Datalist and solved my problem, thanks for the help.

  • @Danielazevedo good that solved. If the answer helped can accept it, it helps who answers :)

0

The doubt was silly, but I’ll leave here what solved my problem that can help other people. I used Datalist and solved my problem

<p:dataList value="#{monografia.listaLinhaPesquisas}" var="linhaPesquisa">
                    <h:outputText value="#{linhaPesquisa.nome}" />
                </p:dataList>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.