I have a problem with a Datatable. First the data table generates the data of the first 10 records without passing parameters, in each record there is a column with several links of Actions such as Edit, Delete, and see its history. There are also options so that the user can generate a query with different parameters such as Dates, Serial number, etc. The problem is in the Links of actions, when the data is loaded for the first time, the links work very well, but when a query is generated with user parameters, the links pass a parameter different from the one that is being selected, for example, I select register 10 and send me to Edit record 15.
I'm using Primefaces 6.0, here's the JSF:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" template="WEB-INF/template.xhtml">
<ui:define name="head">
<style type="text/css">
.grid-pad .ui-panelgrid-content .ui-panelgrid-cell.ui-grid-col-12 {
padding-bottom: 10px;
}
</style>
</ui:define>
<ui:define name="content">
<div class="ui-g">
<div class="ui-g-12">
<div class="card centerText">
<h1 class="lightBlack">CONSULTA DE RESGUARDOS</h1>
<p class="lightBlack"></p>
<h:form>
<p:growl id="growl" showDetail="true" />
<input type="hidden" name="nombreUserLog" id="nombreUserLog" value="#{loginMB.nombre}" />
<h:panelGrid columns="4" layout="grid" style="width: 100%" cellpadding="10">
<p:outputLabel>Número de Serie</p:outputLabel>
<p:outputLabel>Fecha Inicial</p:outputLabel>
<p:outputLabel>Fecha Final</p:outputLabel>
<p:outputLabel></p:outputLabel>
<p:inputText id="numSerie" value="#{resguardoMB.numSerie}"></p:inputText>
<p:calendar id="fechaAsignInicio" value="#{resguardoMB.fechaAsignInicio}" pattern="dd-MM-yyyy" mask="true" />
<p:calendar id="fechaAsignFinal" value="#{resguardoMB.fechaAsignFinal}" pattern="dd-MM-yyyy" mask="true" />
<p:button rendered="#{loginMB.resguardo_rol eq ('SUPERADMIN' or 'ADMIN')}" value="Nuevo Resguardo" outcome="createResguardo"></p:button>
<p:outputLabel>Nombre de Staff</p:outputLabel>
<p:outputLabel>Tipo de Resguardo</p:outputLabel>
<p:outputLabel></p:outputLabel>
<p:outputLabel></p:outputLabel>
<p:selectOneMenu id="userAsign" value="#{resguardoMB.userAsign}">
<f:selectItem itemValue="" itemLabel="-- Seleccione --" />
<f:selectItems value="#{usersMB.usersList}" var="userasign" itemValue="#{userasign.nombre}" itemLabel="#{userasign.nombre}"/>
</p:selectOneMenu>
<p:selectOneMenu id="tipoResguardo" value="#{resguardoMB.tipoResguardo}">
<f:selectItem itemLabel="-- Seleccione --" itemValue=""/>
<f:selectItem itemLabel="Usuario" itemValue="Usuario"/>
<f:selectItem itemLabel="TI" itemValue="TI"/>
</p:selectOneMenu>
<p:commandButton value="Buscar" update="@form" ajax="false"></p:commandButton>
<p:outputLabel></p:outputLabel>
</h:panelGrid>
<p:separator/>
<p:dataTable tableStyle = "table-layout: auto;" id="Resguardos" var="resguardo"
value="#{resguardoMB.resguardoList}" style="width: 100%">
<p:column>
<f:facet name="header">
<h:outputText value="#" />
</f:facet>
<h:outputText value="#{resguardo.idResguardo}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Número de Serie" />
</f:facet>
<h:outputText value="#{resguardo.numSerie}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nombre del Staff" />
</f:facet>
<h:outputText value="#{resguardo.userAsign}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Tipo Resguardo" />
</f:facet>
<h:outputText value="#{resguardo.tipoResguardo}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="País" />
</f:facet>
<h:outputText value="#{resguardo.paisUserAsign}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Estado" />
</f:facet>
<h:outputText value="#{resguardo.descEstado}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Fecha de Asignación" />
</f:facet>
<h:outputText value="#{resguardo.fechaAsignacion}">
<f:convertDateTime pattern="dd-MM-yyyy"></f:convertDateTime>
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Acciones" />
</f:facet>
<p:commandLink action="#{resguardoMB.consultaResguardo(resguardo.idResguardo)}">
<h:outputText value="Ver "/>
</p:commandLink>
<p:outputLabel rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN' or (loginMB.resguardo_rol eq 'ADMIN' and resguardo.descEstado eq 'Activo')}">-</p:outputLabel>
<p:commandLink rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN' or (loginMB.resguardo_rol eq 'ADMIN' and resguardo.descEstado eq 'Activo')}" action="#{resguardoMB.getResguardoByID(resguardo.idResguardo)}" ajax="false">
<h:outputText value=" Editar " />
</p:commandLink>
<p:outputLabel rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN'}">-</p:outputLabel>
<p:commandLink rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN'}" action="#{resguardoMB.deleteResguardo(resguardo.idResguardo)}" update="@form">
<h:outputText value=" Archivar " />
</p:commandLink>
<p:outputLabel rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN' or rol eq 'ADMIN'}">-</p:outputLabel>
<p:commandLink rendered="#{loginMB.resguardo_rol eq 'SUPERADMIN' or rol eq 'ADMIN'}" action="#{resguardohistMB.getResguardohistList(resguardo.idResguardo)}" >
<h:outputText value=" Histórico " />
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
</div>
</div>
</div>
</ui:define>
</ui:composition>
This is the method that is called to fill the datatable:
public List<Resguardo> getResguardoList() {
if (null == getNumSerie() && null == getFechaAsignInicio() && null == getFechaAsignFinal()
&& null == getUserAsign() && null == getTipoResguardo()) {
resguardoList = new ArrayList<Resguardo>();
resguardoList.addAll(getResguardoService().getAllResguardos());
} else {
if (null != getNumSerie() & !"".equals(getNumSerie())) {
resguardoList = new ArrayList<Resguardo>();
resguardoList.addAll(getResguardoService().getResguardoListByNumSerie(getNumSerie()));
setNumSerie("");
} else if (null != getUserAsign() & !"".equals(getUserAsign())) {
resguardoList = new ArrayList<Resguardo>();
resguardoList.addAll(getResguardoService().getResguardoListByUserAsign(getUserAsign()));
setUserAsign("");
} else if (null != getTipoResguardo() & !"".equals(getTipoResguardo())) {
resguardoList = new ArrayList<Resguardo>();
resguardoList.addAll(getResguardoService().getResguardoListByTipoResg(getTipoResguardo()));
setTipoResguardo("");
} else if ((null != getFechaAsignInicio() & !"".equals(getFechaAsignInicio()))
&& (null != getFechaAsignFinal() & !"".equals(getFechaAsignFinal()))) {
resguardoList = new ArrayList<Resguardo>();
resguardoList.addAll(getResguardoService().getResguardoListByFechas(sdf.format(getFechaAsignInicio()),
sdf.format(getFechaAsignFinal())));
setFechaAsignInicio(null);
setFechaAsignFinal(null);
}
}
for(Resguardo resg : resguardoList){
if(resg.getIndEstado() == '1'){
resg.setDescEstado("Activo");
}else{
resg.setDescEstado("Archivado");
}
}
setIdResguardo(0);
return resguardoList;
}
This is the method that is called for the historical, as it was commented when the list is loaded without parameters, the correct record is shown when the link is clicked, when the query with parameters is requested, the record is shown wrong:
public String getResguardohistList(int idResguardo){
log.info("Obteniendo ID");
log.info(idResguardo);
resguardoHistList = new ArrayList<Resguardohist>();
resguardoHistList.addAll(getResguardohistService().getByIdResguardo(idResguardo));
for(Resguardohist resg : resguardoHistList){
if(resg.getIndEstado() == '1'){
resg.setDescEstado("Activo");
}else{
resg.setDescEstado("Archivado");
}
}
return "historicoResguardo";
}
Please, if someone can help me, I would really appreciate it.
Thanks to everyone