2
I’m having trouble formatting a datatable with a fixed column and x
variable columns.
POJO
@Entity
@Table(name="avaliaprojeto", schema="somore")
public class AvaliaProjeto implements Serializable, SampleEntity {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int idAvaliaProjeto;
@OneToOne
@JoinColumn(name="idProjeto")
private Projeto projeto;
@OneToOne
@JoinColumn(name="idCriterio")
private Criterio criterio;
@OneToOne
@JoinColumn(name="idEscala")
private Escala escala;
double valorCriterio;
//gets sets equals e hash
}
There is a list of objects Avaliaprojeto, several linked to the same project. This object aims to relate Criterion-Scale. The goal is to present in a datatable in the following format:
However, when I enter more than one project, the formatting is changed to:
Realize that they are Evaluative objects that deal with exactly the same criteria, varying only their impacts/values.
The view used to create these templates and to register (via dialog) is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:sec="http://www.springframework.org/security/facelets/tags"
template="/resources/templates/template_restrito_menuSomore_processo.xhtml">
<ui:define name="section">
<br />
<center>
<h:outputLabel value="Avaliação de Projeto" class="title" />
</center>
<br />
<h:form id="form">
<p:commandButton value="Novo" icon="ui-icon-document"
actionListener="#{topsisBean.novoAvaliaProjeto}" process="@this"
update="dataTable" oncomplete="PF('avaliaProjetoDialog').show()"
class="botaoDataTable">
<p:resetInput target="avaliaProjeto-dialog" />
</p:commandButton>
<p:commandButton icon="ui-icon-pencil" id="btnEditar" title="Editar"
disabled="#{topsisBean.avaliaProjeto == null}"
class="botaoDataTable" process="@this"
update="dataTable :form btnEditar btnExcluir"
oncomplete="PF('avaliaProjetoDialog').show()">
<p:resetInput target="avaliaProjeto-dialog" />
</p:commandButton>
<p:commandButton icon="ui-icon-trash" id="btnExcluir" title="Excluir"
disabled="#{topsisBean.avaliaProjeto == null}"
class="botaoDataTable" action="#{topsisBean.excluirAvaliaProjetos}"
process="@this" update="dataTable btnExcluir btnEditar" />
<p:commandButton icon="ui-icon-triangle-1-w" id="btnAnterior"
title="Etapa Anterior" disabled="#{topsisBean.pd == null}"
class="botaoDataTable" action="criterio" process="@this"
update="dataTable btnExcluir btnEditar" />
<p:commandButton icon="ui-icon-calculator" id="btnProximo"
title="Calcular TOPSIS" disabled="#{topsisBean.pd == null}"
class="botaoDataTable" action="avaliaProjeto" process="@this"
update="dataTable btnExcluir btnEditar" />
<p:dataTable var="p" value="#{topsisBean.getProjetosPD(true)}"
paginator="true" rows="10" class="dataTable" id="dataTable"
emptyMessage="Nenhuma Avaliação de Projeto cadastrada"
paginatorPosition="bottom" selection="#{topsisBean.projeto}"
selectionMode="single" rowKey="#{p.idProjeto}">
<p:ajax event="rowSelect" updtate=":form:btnExcluir" />
<p:ajax event="rowUnselect" updtate=":form:btnExcluir" />
<p:column headerText="Projeto">
<h:outputText value="#{p.nomeProjeto}" />
</p:column>
<p:columns value="#{topsisBean.avaliaProjetos}" var="ap" headerText="#{ap.criterio.nomeCriterio}">
<h:outputText value="#{topsisBean.verificarTipoCriterio(ap)}" />
</p:columns>
</p:dataTable>
<p:dialog header="Avaliação de Projeto"
widgetVar="avaliaProjetoDialog" modal="true" resizable="false"
id="avaliaProjeto-dialog" closeOnEscape="true">
<p:messages/>
<p:panelGrid>
<p:row>
<p:column style="width:15% !important;">
<h:outputLabel for="pdMenu" value="Processo de Decisão: "
class="componentePF label bold" />
</p:column>
<p:column style="width:100% !important;">
<p:selectOneMenu id="pdMenu" converter="generic"
value="#{topsisBean.pd}" class="componentePF text bold"
required="true"
requiredMessage="É necessário escolher um processo de decisão">
<f:selectItem itemLabel="Escolha um Processo"
noSelectionOption="true" />
<f:selectItems value="#{topsisBean.pds}" var="pd"
itemLabel="#{pd.nomePD}" itemValue="#{pd}" converter="generic" />
<p:ajax listener="#{topsisBean.mudouPD}"
update="projetoMenu dataTableDialog" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column>
<h:outputLabel for="projetoMenu" value="Projeto: "
class="componentePF label bold"
onclick="#{topsisBean.getProjetosPD()}" />
</p:column>
<p:column>
<p:selectOneMenu id="projetoMenu" converter="generic"
value="#{topsisBean.projeto}"
class="componentePF text">
<f:selectItem itemLabel="Escolha um Projeto" itemDisabled="true"
noSelectionOption="true" />
<f:selectItems value="#{topsisBean.projetosPD}" var="p"
itemLabel="#{p.nomeProjeto}" itemValue="#{p}"
converter="generic" />
</p:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:dataTable var="ap" value="#{topsisBean.avaliaProjetosPD}" style="width:100%; margin:0% !important;"
paginator="true" rows="10" class="dataTable" id="dataTableDialog"
emptyMessage="Nenhum Critério Cadastrado no PD #{topsisBean.pd.nomePD}" paginatorPosition="bottom">
<p:column headerText="Critério">
<h:outputText value="#{ap.criterio.nomeCriterio}"/>
</p:column>
<p:column headerText="Valor Numérico (Se houver)" width="220">
<p:spinner value="#{ap.valorCriterio}" min="0" prefix="U$D " class="componentePF text"/>
</p:column>
<p:column id="colEscala" headerText="Escala" width="300">
<p:selectOneMenu converter="generic" value="#{ap.escala}"
class="componentePF text">
<f:selectItem itemLabel="Escolha um Impacto de Escala" itemDisabled="true" noSelectionOption="true" />
<f:selectItems value="#{topsisBean.escalas}" var="e"
itemLabel="#{e.impactoEscala}" itemValue="#{e}" converter="generic" />
</p:selectOneMenu>
</p:column>
</p:dataTable>
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:commandButton value="Cadastrar" icon="ui-icon-disk"
action="#{topsisBean.cadastrarAvaliaProjetos}"
id="cadastrarAvaliaProjeto" ajax="false"
style="width:23% !important; float:right !important;"
class="componentePF button"
rendered="#{topsisBean.pd != null}"/>
</p:column>
</p:row>
</p:panelGrid>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
The table is assembled in the following section of the above mentioned view:
<p:dataTable var="p" value="#{topsisBean.getProjetosPD(true)}"
paginator="true" rows="10" class="dataTable" id="dataTable"
emptyMessage="Nenhuma Avaliação de Projeto cadastrada"
paginatorPosition="bottom" selection="#{topsisBean.projeto}"
selectionMode="single" rowKey="#{p.idProjeto}">
<p:ajax event="rowSelect" updtate=":form:btnExcluir" />
<p:ajax event="rowUnselect" updtate=":form:btnExcluir" />
<p:column headerText="Projeto">
<h:outputText value="#{p.nomeProjeto}" />
</p:column>
<p:columns value="#{topsisBean.avaliaProjetos}" var="ap" headerText="#{ap.criterio.nomeCriterio}">
<h:outputText value="#{topsisBean.verificarTipoCriterio(ap)}" />
</p:columns>
</p:dataTable>
If you need anything else, please let me know.
your method
topsisBean.avaliaProjetos
returns what exactly?– Maicon Carraro
A list of objects of the Avaliaprojeto type.
– HDeiro
In this case, each row of this table is equivalent to five records in the database. That is, I believe that the problem with two columns is due to the fact that this method returns ten records from the database (5 referring to each project). Only nine appear due to the fact that Project is outside the <p:Columns>
– HDeiro
actually on that
value
you should return only the columns and not the list with the objects, take a look at this example here– Maicon Carraro
Got it. The problem is that if I put the list of objects in the datatable it will get a lot of unwanted lines. Each project has 5 objects evaluatedProject. Have any idea what you can do?
– HDeiro
If you look at the link I sent it actually has 2 different lists, one for the columns and the other with the data
– Maicon Carraro
But that’s it. The thing is, in my case, there are three lists. One (number of rows) is the projects, one is the columns and the other is the column values. : p
– HDeiro