Datatable is not updated after actionListener - jsf

I'm facing some problem updating my dataTable when I perform a filter operation with this:
<p:panel styleClass="card" header="Filtri">
<h:panelGrid columns="4" layout="grid"
styleClass="ui-panelgrid-blank form-group">
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="orderMinFilter" label="N. bolla più basso"
value="#{productionOrdersView.orderNumberStartFilter}">
</p:inputText>
<p:outputLabel for="orderMinFilter" value="N. bolla più basso" />
</h:panelGroup>
<h:panelGroup styleClass="md-inputfield">
<p:inputText id="orderMaxFilter" label="N. bolla più alto"
value="#{productionOrdersView.orderNumberEndFilter}">
</p:inputText>
<p:outputLabel for="orderMaxFilter" value="N. bolla più alto" />
</h:panelGroup>
<p:commandButton value="Cancella filtri" icon="ui-icon-clear"
styleClass="red-btn flat"
actionListener="#{productionOrdersView.clearFilter()}"
style="width:auto;margin-bottom:10px; float:right;"
update="dtOrders" />
<p:commandButton value="Cerca" icon="ui-icon-search"
styleClass="primary-btn flat"
actionListener="#{productionOrdersView.filter()}"
update="dtOrders"
style="width:auto;margin-bottom:10px; float:right;" />
</h:panelGrid>
</p:panel>
This is my dataTable:
<p:dataTable id="dtOrders" var="productionOrder"
value="#{productionOrdersView.orders}" selectionMode="single"
reflow="true" selection="#{productionOrdersView.selected}"
filteredValue="#{productionOrdersView.filtered}"
widgetVar="ordersTable" rowKey="#{productionOrder.pk}"
emptyMessage="Nessun elemento oppure la ricerca è ancora attiva..."
paginator="true" rows="20">
And this is the method:
public void filter() {
if (orderNumberStartFilter != null && orderNumberEndFilter != null) {
this.orders = productionOrderController.findFromToOrderNumber(Integer.valueOf(orderNumberStartFilter),
Integer.valueOf(orderNumberEndFilter));
this.filtered = orders;
}
}
The filter() method is executed correctly and the list in the bean are correct (I search for 11 elements and I got it), but the dataTable is updated but not with these values; why? Where am I wrong?

You add form tag to update property of commandButton.
<p:commandButton value="Cerca" icon="ui-icon-search"
styleClass="primary-btn flat"
actionListener="#{productionOrdersView.filter()}"
update=":formName:dtOrders"
style="width:auto;margin-bottom:10px; float:right;" />
.

Related

Multiple JSF progressBar inside same component

I´m trying to show the progress of several batch processes using a progressbar for each one of them. The problem is that only one progressbar is been sent to server side (the last one). Here is the code...
I made a RequestScoped Named bean for the progress beacause I read that for multiple progressBar it is needed a bean instance for each one of the progressbars, but that do not resolve my problem.
I'm using Primefaces 6.1 with JSF 2.2.
Any ideas? Thanks!
<h:form id="formExecutions">
<p:dataGrid id="jobs" value="#{jobExecutorController.jobExecutions}" var="job" rows="5" paginator="true" emptyMessage="#{MessageResources['text.noRecordsFound']}"
paginatorPosition="bottom" columns="1" layout="grid">
<f:facet name="header">
#{MessageResources['text.batchProcesses']}
</f:facet>
<p:outputPanel layout="block" >
<p:panelGrid cellpadding="5" styleClass="vf-panelGrid">
<p:row style="width:100%">
<p:column>
<p:outputLabel for="executionId" value="#{MessageResources['text.executionId']}:" style="font-weight:bold"/>
</p:column>
<p:column>
<h:outputText id="executionId" value="#{job.executionId}" />
</p:column>
<p:column>
<p:outputLabel for="name" value="#{MessageResources['text.name']}:" style="font-weight:bold"/>
</p:column>
<p:column style="width:10%">
<h:outputText id="name" value="#{job.name}"/>
</p:column>
<p:column style="width:50%" rowspan="2">
<p:progressBar id="progressBar" widgetVar="progressBar" ajax="true" value="#{progressController.progress(job)}" labelTemplate="{value}%" styleClass="animated" style="height: 20px; line-height: 20px;" global="false" interval="3000">
<p:ajax event="complete" listener="#{progressController.onCompleteJob(job)}" update="messageDisplay" process="#this"/>
<p:ajax update="jobInfo"/>
</p:progressBar>
</p:column>
<p:column style="width:4%" />
<p:column rowspan="2" style="text-align:right">
<p:commandButton id="restart" onclick="PF('confirmRestartJob').show()" styleClass="coloured-icons-batch restart-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="restart" value="#{MessageResources['text.restartJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="stop" onclick="PF('confirmStopJob').show()" styleClass="coloured-icons-batch stop-image-icon blink"
disabled="#{not job.enableStop}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="stop" value="#{MessageResources['text.stopJobExecution']}" position="top"></p:tooltip>
<p:spacer width="10" />
<p:commandButton id="abandon" onclick="PF('confirmAbandonJob').show()" styleClass="coloured-icons-batch abandon-image-icon blink"
disabled="#{not job.enableRestartAbandon}" immediate="true" title="">
<f:setPropertyActionListener value="#{job.executionId}" target="#{jobExecutorController.executionIdSelected}" />
<f:setPropertyActionListener value="#{job.name}" target="#{jobExecutorController.executionNameSelected}" />
</p:commandButton>
<p:tooltip for="abandon" value="#{MessageResources['text.abandonJobExecution']}" position="top"></p:tooltip>
</p:column>
</p:row>
</p:panelGrid>
<h:panelGroup id="jobInfo" >
<p:panelGrid columns="4" cellpadding="5" styleClass="vf-panelGrid">
<p:outputLabel for="creationDate" value="#{MessageResources['text.creationDate']}:" style="font-weight:bold"/>
<h:outputText id="creationDate" value="#{job.formattedDate(job.createdDate)}" />
<p:outputLabel for="startDate" value="#{MessageResources['text.dateStartProcess']}:" style="font-weight:bold"/>
<h:outputText id="startDate" value="#{job.formattedDate(job.startedDate)}" />
<p:outputLabel for="lastUpdate" value="#{MessageResources['text.lastUpdate']}:" style="font-weight:bold"/>
<h:outputText id="lastUpdate" value="#{job.formattedDate(job.lastUpdate)}" />
<p:outputLabel for="toProcess" value="#{MessageResources['text.itemsToProcess']}:" style="font-weight:bold"/>
<h:outputText id="toProcess" value="#{job.itemsToProcess}" />
<p:outputLabel for="endDate" value="#{MessageResources['text.ended']}:" style="font-weight:bold"/>
<h:outputText id="endDate" value="#{job.formattedDate(job.endedDate)}" />
<p:outputLabel for="processed" value="#{MessageResources['text.itemsProcessed']}:" style="font-weight:bold"/>
<h:outputText id="processed" value="#{job.itemsProcessed}" />
<p:outputLabel for="status" value="#{MessageResources['text.state']}:" style="font-weight:bold"/>
<h:outputText id="status" value="#{job.status}" />
</p:panelGrid>
</h:panelGroup>
</p:outputPanel>
<p:spacer width="5"/>
<p:separator />
<p:spacer width="5"/>
</p:dataGrid>
My RequestScope backing bean...
#Named("progressController")
#RequestScoped
public class ProgressController
{
#EJB
private EJBJobRepositoryLocal ejbJobRepository;
public Long progress(DMJob jobExecution) throws VfCmsSqlException
{
if (jobExecution.getStatus().equals(BatchStatus.STARTED.name())) {
jobExecution.setProgress(ejbJobRepository.getJobProgress(jobExecution.getExecutionId()));
}
PrimeUtil.get().update("formExecutions:jobInfo");
return jobExecution.getProgress();
}
public void onCompleteJob(DMJob jobExecution)
{
Object[] parameters = {jobExecution.getName(), jobExecution.getExecutionId()};
Messages.displayInfoMessage("text.jobComplete", parameters);
}
}
Ok. The problem is that the PrimeFaces().start() method is not been executed over all the components generated by JSF. So, what I did is a javascript function which is executed when the page is fully loaded. In my case the components that I needed to initialize are several progress bar. My components are inside a data scroller which is inside a form, that's why I concat those id's. The 'i' is the index of each of the rendered progress bar in the page.
<script type="text/javascript">
$(window).load(function() {
startProgress();
});
function startProgress(){
var pid = document.getElementsByClassName('ui-progressbar');
var pidLength = pid.length;
for (var i = 0; i < pidLength; i++) {
var id = "formExecutions:scroller:".concat(i).concat(":progressBar");
PrimeFaces.getWidgetById(id).start();
}
}
</script>
And that was all!

Calling two dialog and save in two methods in JSF

I have two buttons and two dialog, each button calls a dialog, each dialog has a save button, you send two different methods in the Bean. The problem is that it only works sending a dialog and not the other.
xhtml
<h:form id='form1'>
<p:panel id="basic" header="#{usuarioBean.nompagina}" footer="" style="margin-bottom:20px">
<p:panelGrid columns="3" style="width: 100%">
<p:commandButton value="Nuevo" icon="ui-icon-document" actionListener="#{menuBean.setAccion('Registrar')}" type="button" onclick="PF('dlg').show();" update=":dialog"/>
</p:panelGrid>
.......
<p:column headerText="Acción">
<p:commandButton value="Asignar Rol" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('wdatosvar').show()" update=":wdatosid" icon="ui-icon-person"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
<p:dialog position="center top" styleClass="ui-widget-container" id="dialog" header="Usuarios" widgetVar="dlg" dynamic="true" modal="true" width="400">
<h:form>
<p:panelGrid columns="2">
...
<p:commandButton value="Guardar" actionListener="#{usuarioBean.inUsuario()}" oncomplete="handleDialogSubmit2(args)" update=":form1:listusuario" icon="ui-icon-check" />
<p:commandButton value="Cancelar" immediate="true" onclick="PF('dlg').hide();" icon="ui-icon-cancel" />
<p:outputLabel id="refresc" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog header="Datos" position="center top" widgetVar="wdatosvar" id="wdatosid" modal="true" showEffect="explode" hideEffect="explode">
<h:form>
<h:panelGrid columns="2">
...
<p:commandButton value="Guardar" actionListener="#{usuarioBean.saveUsuario()}" oncomplete="handleDialogSubmit(xhr, status, args)" update=":form1:listusuario,#form,refrescar" icon="ui-icon-check" />
<p:commandButton value="Cancelar" immediate="true" onclick="PF('wdatosvar').hide();" icon="ui-icon-cancel" />
<p:outputLabel id="refrescar" />
</h:panelGrid>
</h:form>
</p:dialog>
And usuarioBean.java
#ManagedBean
#SessionScoped
public class usuarioBean {
public void saveUsuario() throws Exception {
usuariohistorialDAO dao = new usuariohistorialDAO();
try {
dao.insertCredencial(usuariohis,value1);
this.listarUsuarios(palabra);
} catch (Exception e) {
throw e;
}
}
public void inUsuario() throws Exception{
usuariohistorialDAO dao = new usuariohistorialDAO();
try {
dao.insertarUsuario(usuariohis);
this.listarUsuarios(palabra);
} catch (Exception e) {
throw e;
}
}
}
inUsuario does no work.
Do not know exactly why but this form solves my problem
<h:form id='form1'>
<p:panel id="basic" header="Lista de Usuarios" footer="" style="margin-bottom:20px">
<p:panelGrid columns="3" style="width: 100%">
<p:commandButton value="Nuevo" icon="ui-icon-document" oncomplete="PF('dlg').show()" update=":dialog"/>
</p:panelGrid>
<p:inputText value="#{usuarioBean.palabra}" id="search" class="inputmediano"/>
<p:commandButton value="Buscar" icon="ui-icon-refresh" actionListener="#{usuarioBean.bucarUsuario()}" update="listusuario"/>
<p:dataTable tableStyleClass="ui-table-columntoggle" var="rowusu" value="#{usuarioBean.arrayusu}" paginator="true" paginatorPosition="bottom" rows="30" id="listusuario" style="width: 100%;margin-top: 10px" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<p:column headerText="Id" style="width: 25px">
<h:outputText value="#{rowusu.ush_id}"/>
</p:column>
<p:column headerText="Usuario" >
<h:outputText value="#{rowusu.usu_nombre}"/>
</p:column>
<p:column headerText="Sexo" >
<h:outputText value="#{rowusu.usu_sexo}"/>
</p:column>
<p:column headerText="Nick">
<h:outputText value="#{rowusu.ush_correo}" />
</p:column>
<p:column headerText="Rol">
<h:outputText value="#{rowusu.nomrol}"/>
</p:column>
<p:column headerText="Cargo">
<h:outputText value="#{rowusu.nomcargo}"/>
</p:column>
<p:column headerText="Acción">
<p:commandButton value="Asignar Rol" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('wdatosvar').show()" update=":wdatosid" icon="ui-icon-person"/>
<p:commandButton value="Modificar" actionListener="#{usuarioBean.leerUsuario(rowusu)}" oncomplete="PF('dlg').show()" update=":dialog" icon="ui-icon-person"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>

Missing value in modal dialog in edit mode

I'm newbie in Java and PrimeFaces (I have worked only with c# and visual sudio).
When I try to edit a row, column value isn't displayed in modal dialog.
I've tried different solution, same result.
Can someone help me?
<ui:include src="/includes/header.xhtml" />
<!-- Container -->
<div id="container">
<div class="shell">
<div id="main" style="vertical-align: middle;">
<br /> <br />
<form>
<p:dataTable var="loc" value="#{location.loc}" rowKey="#{loc.code}" id='loca'>
<p:column width="100">
<p:commandButton icon="ui-icon-plus" type="button" id="add" onclick="PF('newDialog').show()" update="Newform:NewLocation"/>
<p:commandButton icon="ui-icon-pencil" type="button" update="updForm:updDisplay" onclick="PF('updDialog').show()" id="edit" ajax="true">
</p:commandButton>
<p:commandButton icon="ui-icon-trash" />
</p:column>
<p:column headerText="Code">
<h:outputText value="#{loc.code}" />
</p:column>
<p:column headerText="Ip">
<h:outputText value="#{loc.address}" />
</p:column>
<p:column headerText="Descrizione">
<h:outputText value="#{loc.description}" />
</p:column>
</p:dataTable>
</form>
<p:dialog widgetVar="newDialog" header="Insert Location" width="430" height="220" modal="true">
<h:form id="Newform">
<p:outputPanel id="NewLocation">
<h:panelGrid columns="2">
<h:outputLabel value="Code" />
<p:inputText value="#{loc.Code}"></p:inputText>
<h:outputLabel value="description" />
<p:inputText value="#{loc.description}"></p:inputText>
<h:outputLabel value="Address" />
<p:inputText value="#{loc.address}"></p:inputText>
</h:panelGrid>
<p:commandButton value="Save" onclick="newDialog.close()">
</p:commandButton>
</p:outputPanel>
</p:dialog>
<p:dialog widgetVar="updDialog" header="Location" width="430" height="220" modal="true">
<h:form id="updForm">
<p:outputPanel id="updDisplay">
<h:inputHidden value="#{loc.code}" />
<h:panelGrid columns="2">
<h:outputLabel value="Description" />
<p:inputText value="#{loc.description}"></p:inputText>
<h:outputLabel value="Address" />
<p:inputText value="#{loc.address}"></p:inputText>
</h:panelGrid>
<p:commandButton value="Update" onclick="updDialog.close()">
</p:commandButton>
<p:commandButton value="Delete" onclick="updDialog.close()">
</p:commandButton>
<p:growl id="growl" showDetail="true" />
</p:outputPanel>
</h:form>
</p:dialog>
MangedBean:
#ManagedBean (name="Locations")
#SessionScoped
public class Locations {
#EJB
cslocationBeanRemote locationsBean;
private List<cslocationModel> ListLocations;
#SuppressWarnings({"unchecked", "rawtypes"})
#PostConstruct
public void init() {}
public List<cslocationModel> getListLocations() {
try {
ArrayList orderBy = new ArrayList();
orderBy.add(cslocationModel.ORDERcodASC);
setListLocations((List<cslocationModel>) locationsBean.find(null,
null, null, orderBy));
} catch (Exception ecc) {
ecc.printStackTrace();
}
return ListLocations;
}
public void setListLocations(List<cslocationModel> ListLocations) {
this.ListLocations = ListLocations;
}
}
Thank you.

Datatable link to edit record only works once unless I hit refresh

working with a Primefaces data table and dialog. Each record in data table has a link as such:
<p:commandLink value="#{item.pk}" update=":itemUpdateForm:display"
onclick="PF('itemUpdateDialog').show();" title="Edit">
<f:setPropertyActionListener value="#{item}"
target="#{itemController.selecteditem}" />
</p:commandLink>
The link opens a primefaces dialog successfully the first time but after I submit the form in this popup dialog, which updates that recordset, the links in the datatable will no longer open the dialog again unless I hit refresh on the browser.
Here is the update button in the p:dialog:
<f:facet name="footer">
<p:commandButton value="Update" update=":ItemListForm:dataTable, :growl"
oncomplete=" handleSubmitRequest(xhr, status, args, 'itemDlg','itemUpdateForm');"
actionListener="#{itemController.doUpdateItem()}" />
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
And scopes/pertinent code:
itemController
#ManagedBean
#ViewScoped
public class ItemController implements Serializable {
#PostConstruct
public void init() {
items= itemListProducer.getItems();
}
public void doUpdateItem() {
itemRepository.update(selectedItem);
itemEventSrc.fire(selectedItem);
items = itemListProducer.getitems();
Messages.addAjaxMessage("Update Operation Was Successful!");
}
List Producer
#ApplicationScoped
public class ItemListProducer implements Serializable {
Edit
per comment here is DataTable and the Primefaces update dialog
<h:form id="ItemListForm">
<p:dataTable id="dataTable" var="item"
value="#{itemController.items}"
paginator="true" rows="10"
selection="#{itemController.selectedItems}" rowKey="#{item.oc_id}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
lazy="false" rowsPerPageTemplate="10,15,50">
<f:facet name="header">
Items (#{itemController.items.size()})
</f:facet>
<p:column selectionMode="multiple" style="width:18px"/>
<p:column filterBy="#{item.oc_id}" sortBy="#{item.oc_id}">
<f:facet name="header"><h:outputText value="OC #" /></f:facet>
<p:commandLink value="#{item.pk}" update=":itemUpdateForm:display" onclick="PF('itemUpdateDialog').show();" title="Edit">
<f:setPropertyActionListener value="#{item}" target="#{itemController.selecteditem}" />
</p:commandLink>
</p:column>
more p:columns
<f:facet name="footer">
<p:commandButton value="New item" onclick="PF('dlg1').show();" title="Creates new Item" />
<p:commandButton value="Delete Selected Items"
actionListener="#{itemController.doDeleteItems}"
update="#form, :growl">
<p:confirm header="Confirmation" message="Are you sure you want to remove the selected Items?" />
</p:commandButton>
</f:facet>
</p:dataTable>
<p:confirmDialog global="true">
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
</h:form>
... and dialog
<p:dialog header="Item Update Form" widgetVar="itemUpdateDialog" resizable="false" id="itemDlg">
<h:form id="itemUpdateForm">
<p:panel>
<p:panelGrid id="display" columns="3" cellpadding="4"
style="margin:0 auto;">
<h:outputText value="Title :"></h:outputText>
<p:inputText id="title" value="#{itemController.selectedItem.title}"
required="true"
requiredMessage="Please Enter Title!" />
<p:message for="title" />
other inputs
<f:facet name="footer">
<p:commandButton value="Update" update=":ItemListForm:dataTable, :growl"
oncomplete=" handleSubmitRequest(xhr, status, args, 'itemDlg','itemUpdateForm');"
actionListener="#{itemController.doUpdateItem()}" />
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
</p:panelGrid>
</p:panel>
</h:form>
</p:dialog>
EDIT 2
Thanks to help from Michele's Answer, I determined the issue was related to how I was closing the dialog by its id and not by its widgetVar. I was originally passing in just the id which was used with jQuery effect 'shake', and then closing that object. By adding the widgetVar and using Michele's var d = (typeof dialogWv === "string") ? PF(dialogWv) : dialogWv; I no longer have my issue.
This ultimately works for me:
<p:dialog header="Update Form" widgetVar="itemUpdateDialogWv"
resizable="false" id="itemUpdateDialogId">
<h:form id="itemUpdateForm">
<p:panel>
------content-------
<f:facet name="footer">
<p:commandButton value="Update" update=":ItemListForm:dataTable, :growl"
oncomplete=" handleSubmitRequest(xhr, status, args, 'itemUpdateDialogWv','itemUpdateForm', 'itemUpdateDialogId');"
actionListener="#{itemController.doUpdateItem()}" />
<p:commandButton type="reset" value="Reset"></p:commandButton>
</f:facet>
</p:panelGrid>
</p:panel>
</h:form>
</p:dialog>
function handleSubmitRequest(xhr, status, args, dialogWv, formName, dialogNameId) {
dialog = jQuery('#'+dialogNameId);
var d = (typeof dialogWv === "string") ? PF(dialogWv) : dialogWv;
if(args.validationFailed) {
dialog.effect("shake", { times:5 }, 1000);
} else {
clearForm(formName);
d.hide();
}
}
function clearForm(formName){
jQuery('#'+formName).each(function(){
this.reset();
});
}
Too long for a comment...
You can try:
<p:commandLink value="#{item.pk}" process="#this" update=":itemUpdateForm"
oncomplete="PF('itemUpdateDialog').show();" title="Edit">
<f:setPropertyActionListener value="#{item}" target="#{itemController.selecteditem}" />
</p:commandLink>
specify process="#this": otherwise it defaults to #all and will include the dialog too
use oncomplete instead of onclick
and
<p:commandButton value="Update" process="#form" update="#form, :ItemListForm, :growl"
oncomplete="handleSubmitRequest(xhr, status, args, 'itemDlg','itemUpdateForm');"
actionListener="#{itemController.doUpdateItem}" />
specify process="#form": the same as before
add #form to update: generally is a good practice to update the dialog form tho show validation errors and to close dialog only if not validation failed (I don't know how handleSubmitRequest works, maybe it does exactly this)
However:
No js errors on commandButton click?
Is request fired?
If yes, can you post request params for the not working click?
P.S.
handleSubmitRequest(xhr, status, args, 'itemDlg','itemUpdateForm'); has argument itemDlg. Is it correct?
for completeness here is my hideDialog
function hideDialog(dialog, args, status, xhr)
{
var d = (typeof dialog === "string") ? PF(dialog) : dialog;
if(!args.validationFailed)
{
d.hide();
}
}
which is invoked:
<p:commandButton value="Update" process="#form" update="#form :ItemListForm :growl"
oncomplete="hideDialog('itemUpdateDialog', args)"
actionListener="#{itemController.doUpdateItem}" />

Command link is not working on a form with datatable multiple selection - JSF

I'm having problem with a commamd link that adds a row in a datatable and refreshes it. It was working fine, but when I added another table with multiple selection on the same form, It stopped work. Is there some incompatibility between them?
I'm using PrimeFaces 3.4, Mojarra 2.1.6 and Glassfish 3
Here is my form:
<h2>Projeto para Credenciamento Equipe de Saúde da Família</h2>
<hr />
<h:form id="formCredenciamentoEsf" prependId="false">
<p:fieldset legend="Caracterização Geral">
<p:panelGrid id="microareas" columns="2" cellspacing="8">
<p:dataTable
value="#{credenciamentoEsfMB.credenciamentoESF.projeto.caracterizacaoTerritorialDemograficaList}"
var="carac" emptyMessage="Adicione uma microárea.">
<p:column
headerText="Microáreas que compõem a área de abrangência da ESF">
<p:inputText value="#{carac.microarea}" size="50" />
</p:column>
<p:column
headerText="População Estimada por Microárea (nº de pessoas)">
<p:inputText value="#{carac.populacaoEstimadaMicroarea}"
size="50" />
</p:column>
<p:column>
<p:commandLink
actionListener="#{credenciamentoEsfMB.removerCaracteristica}"
update=":formCredenciamentoEsf:microareas">
<f:setPropertyActionListener value="#{carac}"
target="#{credenciamentoEsfMB.caracteristicaSelecionada}" />
<h:outputText value="Remover " />
</p:commandLink>
</p:column>
</p:dataTable>
</p:panelGrid>
<h:panelGrid columns="2">
<p:commandLink actionListener="#{credenciamentoEsfMB.addCaracteristicaTerritorialDemografica}"
update=":formCredenciamentoEsf:microareas">
<h:outputText value="Adicionar Microárea" />
</p:commandLink>
<h:outputLabel/>
<h:outputLabel
value="População total coberta pela ESF (nº de pessoas):"></h:outputLabel>
<p:inputText id="populacaoCoberta"
value="#{credenciamentoEsfMB.credenciamentoESF.populacaoTotalCoberta}" />
<h:outputLabel
value="Caracterização da população a ser coberta pelas ações da ESF:" />
<p:dataTable
value="#{credenciamentoEsfMB.populacaoCobertaDataModel}" var="pop"
id="dtCaracteristicaPopulacaoCoberta"
selection="#{credenciamentoEsfMB.populacaoCobertaSelecionadas}" >
<p:column selectionMode="multiple" />
<p:column headerText="População a ser atendida">
<h:outputLabel
value="#{pop.caracteristicaPopulacaoCoberta.descricao}" />
</p:column>
<p:column headerText="Nº de pessoas">
<p:inputText value="#{pop.numPessoas}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</p:fieldset>
</h:form>
</ui:define>
The link "Adicionar Microárea" didn't work when I put the last datatable with multiple selection.
Here is my Managed bean:
#ManagedBean
#ViewScoped
public class CredenciamentoEsfMB {
....
public PopulacaoCobertaDataModel getPopulacaoCobertaDataModel() {
List<CaracteristicaPopulacaoCoberta> caracteristicas = caracteristicaPopulacaoCobertaEjb.buscarTodos();
populacaoCobertaEsf = new ArrayList<PopulacaoCobertaESFESB>();
for (CaracteristicaPopulacaoCoberta caracteristicaPopulacaoCoberta : caracteristicas) {
PopulacaoCobertaESFESB p = new PopulacaoCobertaESFESB();
p.setCaracteristicaPopulacaoCoberta(caracteristicaPopulacaoCoberta);
p.setCredenciamentoESFESB(credenciamentoESF);
populacaoCobertaEsf.add(p);
}
this.populacaoCobertaDataModel = new PopulacaoCobertaDataModel(this.populacaoCobertaEsf);
return this.populacaoCobertaDataModel;
}
public void removerCaracteristica() {
credenciamentoESF.getProjeto()
.getCaracterizacaoTerritorialDemograficaList().remove(caracteristicaSelecionada);
}
public void addCaracteristicaTerritorialDemografica(ActionEvent e) {
System.out.println("Adicionando microarea");
credenciamentoESF.getProjeto()
.getCaracterizacaoTerritorialDemograficaList()
.add(new CaracterizacaoTerritorialDemografica());
}
}
Does anyone know what is going on?

Resources