Primefaces datatable not updated after deleting the last row - ajax

Expected function is, I'm deleting a row from my primefaces datatable and adding the deleted list to another datatable. It works fine with the list until it reaches the last row. Actual issue is after deleting the last row it never updates itself datatable (both datatables original and deleted datatable properties list).
Here is the code
<p:outputPanel id="ontProp" styleClass="ontologyProperties">
<p:panelGrid id="propertiesDetail" columns="1" styleClass="ontoProperties"
rendered="#{not empty managebean.listedProperties}" >
<p:outputLabel id="propLabel" value="Available Properties" styleClass="propLabel"/>
<p:dataTable id="properties" scrollable="true" scrollHeight="200" var="prop"
value="#{managebean.listedProperties}" styleClass="propertiesList"
selection="#{managebean.addProperties}" rowKey="#{prop.name}"
rendered="#{not empty managebean.listedProperties}"
rowStyleClass="#{prop.objProp == true ? 'objprop' : null }
#{prop.objProp == false ? 'dataprop' : null}
#{prop.hasRestrictions == true ? 'restriction' : null}">
<p:column selectionMode="multiple" style="width:30px;text-align:center"/>
<p:column headerText="Domain" width="auto">
<div align="center">
<ui:repeat value="#{prop.domains}" var="domain">
<li><h:outputText value="#{domain.name}"/></li>
</ui:repeat>
</div>
</p:column>
<p:column headerText="Property" width="auto">
<div align="center">
<h:outputText id="opPropName" value=" #{prop.name}"/>
</div>
</p:column>
<p:column headerText="Range" width="auto">
<div align="center">
<ui:repeat value="#{prop.objRanges}" var="range">
<li><h:outputText value="#{range.name}"/></li>
</ui:repeat>
</div>
</p:column>
<f:facet name="footer">
<div align="left">
<p:commandButton id="cmdPruneProp" actionListener="#{managebean.savePropertiesForClass()}"
icon="ui-icon-plus" update=":topForm:form:growl :topForm:form:properties
:topForm:form:remProp" value="#{msg['apply.pruneProperties']}" >
</p:commandButton>
</div>
</f:facet>
</p:dataTable>
<p:dataTable id="remProp" scrollable="true" scrollHeight="200" var="prop"
value="#{managebean.selectedProperties}" styleClass="propertiesList"
rowKey="#{prop.name}" rowStyleClass="#{prop.objProp == true ? 'objprop' : null }
#{prop.objProp == false ? 'dataprop' : null} #{prop.hasRestrictions == true ? 'restriction' : null}">
<p:column headerText="Domain" width="auto">
<div align="center">
<ui:repeat value="#{prop.domains}" var="domain">
<li><h:outputText value="#{domain.name}"/></li>
</ui:repeat>
</div>
</p:column>
<p:column headerText="Property" width="auto">
<div align="center">
<h:outputText id="rpropName" value=" #{prop.name}"/>
</div>
</p:column>
<p:column headerText="Range" width="auto">
<div align="center">
<ui:repeat value="#{prop.objRanges}" var="range">
<li><h:outputText value="#{range.name}"/></li>
</ui:repeat>
</div>
</p:column>
<p:column headerText="Remove">
<div align="center">
<p:commandButton id="removeButton" icon="ui-icon-closethick" title="Remove"
action="#{managebean.removePropertiesForClass}"
update=":topForm:form:growl :topForm:form:properties
:topForm:form:remProp">
<f:setPropertyActionListener value="#{prop}"
target="#{managebean.ontologicalPropertyDTO}"/>
</p:commandButton>
</div>
</p:column>
</p:dataTable>
</p:panelGrid>
I'm using primefaces 5.1.
Appreciate your help.

you should use a unique identifier for a row, try using another rowKey for both datatbles

Related

primefaces ui is not rendering properly

I'm having a problem with primefaces ui. It doesnt render icon that it was supposed to be rendered when I use and the problem is not happening only on this but also on many other pages. I haven't used jquery.
I dont know what's wrong. Googled it but didnt find an answer.
Here is my code
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/WEB-INF/faces/template.xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf" xmlns:p="http://primefaces.org/ui"
xmlns:prettyfaces="http://ocpsoft.com/prettyfaces">
<ui:param name="title" value="List of Employee"/>
<ui:define name="breadcrum1">
<li><h:link value="Employee Management" outcome="pretty:home"/></li>
<li><h:link value="List Employee Record" outcome="pretty:list_employee"/></li>
</ui:define>
<ui:define name="content">
<div class="container">
<div class="row">
<div class="col-xs-10 col-md-10 span3">
<p:messages id="messages" autoUpdate="true" closable="true" globalOnly="true" style="text-align: center;"/>
<h:form id="form">
<p:dataTable
class="panel-primary table table-condensed"
var="employee" value="#{dtLazyView.lazyModel}" paginator="true" rows="10"
emptyMessage="No Employee found with given criteria"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{dtLazyView.selectedEmployee}" widgetVar="employeeTable" lazy="true">
<f:facet name="header">
Employee Information
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('employeeTable').filter()" style="width:150px" placeholder="Enter keyword"/>
</f:facet>
<p:column headerText="Id">
<h:outputText value="#{employee.employeeCode}" />
</p:column>
<p:column headerText="Employee Name">
<h:outputText value="#{employee.employeeName}" />
</p:column>
<p:column headerText="Employee Mobile Number">
<h:outputText value="#{employee.contact.mobileNumber}" />
</p:column>
<p:column headerText="Employee Role" >
<h:outputText value="#{employee.detail.employeeRole}" />
</p:column>
<p:column headerText="Option">
<h:commandButton action="#{employeeEditController.loadData(employee)}" value="Edit" class="btn btn-primary" style="margin-left: 40px;"> <f:ajax execute="#form"/></h:commandButton>
<p:commandButton update=":form:employeeDetail" oncomplete="PF('employeeDialog').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{employee}" target="#{dtLazyView.selectedEmployee}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Employee Info" widgetVar="employeeDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" styleClass="">
<p:outputPanel id="employeeDetail" style="text-align:center;">
<p:panelGrid columns="2" rendered="#{not empty dtLazyView.selectedEmployee}" columnClasses="label,value">
<f:facet name="header">
<img src="../../imageshandler/#{dtLazyView.selectedEmployee.employeePicture}" class="img-responsive" style="width:200px;height: 200px;margin-left: 100px;border-radius: 50%"/>
</f:facet>
<h:outputText value="Name :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeName}" />
<h:outputText value="DOB :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeDob}" />
<h:outputText value="Gender :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.sex}" style="color:#{dtSelectionView.selectedCar.color}"/>
<h:outputText value="Salary : " style="color: black" />
<h:outputText value="Rs : #{dtLazyView.selectedEmployee.salary.basicSalary}" />
<h:outputText value="Working date :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeDateOfCommencement}"/>
<h:outputText value="Employee Job Specification :" style="color: black"/>
<h:inputTextarea value="#{dtLazyView.selectedEmployee.detail.jobSpecification}" readonly="true"/>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</div>
</div>
</div>
</ui:define>
According to Primefaces, you can use Font Awesome for the icons, so try replacing
icon="ui-icon-search"
with
icon="fa fa-search"
Keep in mind
Font Awesome icons are provided out of the box within PrimeFaces. In
order to enable Font Awesome support, enable primefaces.FONT_AWESOME
setting as true via a context param.

commandButton update attribute not working

I have a commandButton which opens a dialog containing a table.
When the button is clicked the dialog pops out but it does not contain anything.
This is my code:
<h:panelGroup id="correctionsEntries" layout="block">
<p:dataTable styleClass="dataTable" id="entriesTable" var="entry" value="#{bean.tableModel.items}">
<p:columnGroup type="header">
<p:row>
<ui:repeat var="column" value="#{bean.tableModel.columns}" varStatus="colStatus">
<p:column headerText="#{column.header}">
</p:column>
</ui:repeat>
</p:row>
</p:columnGroup>
<c:forEach var="column" items="#{bean.tableModel.columns}">
<c:choose>
<c:when test="${column.header eq 'Upload'}">
<p:column>
<p:commandButton value="Upload" immediate="true" actionListener="#{bean.setSelectedRow(entry)}" oncomplete="PF('upload').show();" />
<p:dialog header="Upload" widgetVar="upload" height="10%" width="80%">
<p:messages binding="#{bean.component}" />
<p:fileUpload fileUploadListener="#{bean.uploadCSV}" />
</p:dialog>
</p:column>
</c:when>
<c:when test="${column.header eq 'Export'}">
<p:column>
<p:commandButton value="Download" immediate="true" ajax="false" actionListener="#{bean.setSelectedRow(entry)}">
<p:fileDownload value="#{bean.downloadCSV()}" />
</p:commandButton>
</p:column>
</c:when>
<c:when test="${column.header eq 'Display'}">
<p:column>
<p:commandButton id="displayButton" value="Display"
immediate="true"
action="#{tableBean.execute(entry)}"
update="displayTable"
oncomplete="PF('dialog').show();" />
<p:dialog id="dialog" header="Current data" widgetVar="dialog" height="80%" width="80%">
<p:dataTable styleClass="dataTable"
id="displayTable" var="tableDataVar"
value="#{tableBean.tableModel.data}"
tableStyle="width:auto;" resizableColumns="true">
<p:columns var="tableHeader" value="#{tableBean.tableModel.headers}">
<f:facet name="header">
<h:outputText value="#{tableHeader}" />
</f:facet>
<h:outputText value="#{tableDataVar[tableHeader]}" />
</p:columns>
</p:dataTable>
</p:dialog>
</p:column>
</c:when>
<c:when test="${column.header eq 'Test'}">
<p:column>
<p:commandButton value="Test" immediate="true" ajax="false" actionListener="#{bean.setSelectedRow(entry)}">
<p:fileDownload value="#{bean.testFilesDownload()}" />
</p:commandButton>
</p:column>
</c:when>
<c:otherwise>
<p:column>
<h:outputText value="#{bean.tableModel.get(entry, column)}" />
</p:column>
</c:otherwise>
</c:choose>
</c:forEach>
</p:dataTable>
</h:panelGroup>
The table is displayed only after refreshing the page.
The problem is that a dialog containing the table is created for each of the column from the parent table.
Therefore there are as many dialog as there are columns.
The fix for this was adding the dialog in a separate form, and referring it in the commandButton by specifying its path.

p:ajaxStatus does not receive oncomplete event from lazy datatable

I'm using Primefaces 3.5 and trying to display a "loading" image while updating a lazy-loaded datatable. In the following AjaxStatus element, the "ajax-loader" image is displayed when datatable is updated by a commandButton action. However when ajax call and table update is completed, the image does not disappear. In other words onComplete event is not received.
<p:ajaxStatus style="width:260px;" id="ajaxStatusPanel">
<f:facet name="start">
<h:graphicImage value="../images/ajax-loader.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
Here is a portion of the form that contains the commandButton and the datatable:
<h:form>
<p:panel toggleable="true" toggleSpeed="300" header="FILTER RESULTS">
<table align="center">
<tr>
<td>NAME: </td>
<td><h:inputText value="#{personBean.personLazyData.paramName}" /></td>
</tr>
<tr>
<td>PLACE OF BIRTH : </td>
<td><h:inputText value="#{personBean.personLazyData.paramPlaceOfBirth}" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<p:commandButton value="Update" global="true"
actionListener="#{personBean.onFilterChanged}"
update="personListTable"/>
</td>
</tr>
</table>
</p:panel>
<p:dataTable id="personListTable" rendered="#{personBean.superUser}" var="person"
value="#{personBean.personLazyData}" emptyMessage="Not found."
paginator="true" rows="20" lazy="true" selection="#{personBean.selectedPersons}" global="true"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="20,50,100">
<f:facet name="header">SURVEYS</f:facet>
<p:column selectionMode="multiple" style="width:2%" />
<p:column headerText="ID" >
<h:outputText value="#{person.id}"/>
</p:column>
<p:column headerText="NAME" >
<h:outputText value="#{person.name}"/>
</p:column>
<p:column headerText="SURNAME" >
<h:outputText value="#{person.surname}" />
</p:column>
</p:dataTable>
Is there anybody who have faced a similar issue?
Another note: In cases where datatable is not rendered (or if I change rendered attribute to false), the loading image is displayed and disappeared for a very short while since no data is retrieved.
The issue is resolved when I updated primefaces version to 4.0

error null pointer JSF transfer data

I made this code here, q aims to list the values ​​of the bank, and that the User can update a date, even through the dataTable. So far, I managed to get to this point, only that, sets the value that the User enters. I can not find this value anywhere in the world, already ran tdo and the value that is typed in the box, does not come. I used several types of variables, but nothing.
<p:dataTable id="dataTable"
var="Arquivo"
paginator="true"
paginatorPosition="bottom"
rowsPerPageTemplate="100"
rows="100"
sortBy="#{Arquivo.id}"
value="#{arquivoBean.dataModelArquivo}"
rowStyleClass="#{Arquivo.pendente eq 1 ? 'ok' : 'erro'}"
>
<p:column headerText="ID">
#{Arquivo.id}
</p:column>
<p:column headerText="Nome">
#{Arquivo.nome}
</p:column>
<p:column headerText="Envio">
#{Arquivo.dataEnvio}
</p:column>
<p:column headerText="Produto" width="10px;">
<h:form id="formProduto">
<p:commandButton icon="ui-icon-circle-zoomout" value=""
action="#{arquivoBean.listarProdutoPorArquivo()}"
oncomplete="prodDialog.show()"
update=":form:dataTableProd"
onclick="listarProd([{name: 'ArquivoId', value:#{Arquivo.id}}]);">
<f:setPropertyActionListener value="#{Arquivo}" target="#{arquivoBean.arquivo}"/>
</p:commandButton>
</h:form>
</p:column>
<p:column headerText="Data" >
<p:inputMask id ="entrada#{cc.clientId}" mask="99/99/9999" value="#{Arquivo.dataEntrada}"
onkeypress="if (event.keyCode === 13) {
test([{name: 'ArquivoId', value:#{Arquivo.id}}]);
return;
};"
size="8">
<f:convertDateTime pattern="dd/MM/yyyy"/>
</p:inputMask>
</p:column>
</p:dataTable>
After much poking around, I found this error inspector elements of chrome, tab networks:
<partial-response id="j_id1"><error><error-name>class java.lang.NullPointerException</error-name><error-message><![CDATA[]]></error-message></error></partial-response>
I fixed remove the form block and put many forms in place a need.
just it make works.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:decorate template="/resources/Template.xhtml">
<ui:define id="content" name="content">
<p:growl id="war"/>
<style type="text/css">
.ok{
color: #336600
}
.erro{
color: #D20005;
}
</style>
<div style="width: 90%; margin-left: auto; margin-right: auto; ">
<h:form id="form">
<br/>
<br/>
<p:panel>
<f:facet name="header">
Lista de Arquivos Armazenados
</f:facet>
<h:form id="pesquisar">
<p:toolbar style="width: 100%;">
<p:toolbarGroup align="left" >
<h:panelGrid columns="1" cellpadding="0">
</h:panelGrid>
</p:toolbarGroup>
<p:toolbarGroup align="right">
<h:panelGrid columns="5" cellpadding="0">
<h:outputLabel value="De: "/>
<p:inputMask mask="99/99/9999" value="#{arquivoBean.dataInicial}" size="10"/>
<h:outputLabel value="Até: "/>
<p:inputMask mask="99/99/9999" value="#{arquivoBean.datafinal}" size="10"/>
<p:commandButton value="Buscar" action="#{arquivoBean.listar()}" update=":form:dataTable" ajax="false"/>
<br/>
<p:selectBooleanCheckbox id="check" value="#{arquivoBean.pendente}"
itemLabel="Pendente">
<p:ajax process="#this" event="change" listener="#{arquivoBean.listarPendente()}" update=":form:dataTable" />
</p:selectBooleanCheckbox>
<p:button value="Ajustar Datas" outcome="/telas/armazenado/listaData.xhtml"/>
</h:panelGrid>
</p:toolbarGroup>
</p:toolbar>
</h:form>
</p:panel>
<br/>
<p:dataTable id="dataTable"
var="Arquivo"
paginator="true"
paginatorPosition="bottom"
rowsPerPageTemplate="100"
rows="100"
sortBy="#{Arquivo.id}"
value="#{arquivoBean.dataModelArquivo}"
rowStyleClass="#{Arquivo.pendente eq 1 ? 'ok' : 'erro'}"
emptyMessage="Você ainda não ativou uma empresa ou não existe postagem para esta Empresa">
<p:column headerText="ID">
#{Arquivo.id}
</p:column>
<p:column headerText="Nome">
#{Arquivo.nomeMury}
</p:column>
<p:column headerText="Envio">
#{Arquivo.dataEnvio}
</p:column>
<p:column headerText="Produto" width="10px;">
<h:form id="formProduto">
<p:commandButton icon="ui-icon-circle-zoomout" value=""
action="#{arquivoBean.listarProdutoPorArquivo()}"
oncomplete="prodDialog.show()"
update=":form:dataTableProd"
onclick="listarProd([{name: 'ArquivoId', value:#{Arquivo.id}}]);">
<f:setPropertyActionListener value="#{Arquivo}" target="#{arquivoBean.arquivo}"/>
</p:commandButton>
</h:form>
</p:column>
</p:dataTable>
<p:dialog closeOnEscape="true"
widgetVar="prodDialog"
modal="true"
header="Lista de Produtos da NF-e"
style="width: 300; height: 500"
position="center">
<p:dataTable
id="dataTableProd"
var="XmlItens"
paginator="true"
paginatorPosition="bottom"
rowsPerPageTemplate="10"
rows="10"
value="#{arquivoBean.listaProd}">
<p:column headerText="ID">
#{XmlItens.id}
</p:column>
<p:column headerText="Nome">
#{XmlItens.descricaoProd}
</p:column>
<p:column headerText="Envio">
#{XmlItens.chaveNfe}
</p:column>
</p:dataTable>
<p:remoteCommand name="test" action="#{arquivoBean.inserirDataNota()}">
<f:setPropertyActionListener value="#{Arquivo}" target="#{arquivoBean.arquivo}"/>
</p:remoteCommand>
<p:remoteCommand name="listarProd" action="#{arquivoBean.listarProdutoPorArquivo()}" update=":form:dataTableProd">
<f:setPropertyActionListener value="#{Arquivo}" target="#{arquivoBean.arquivo}"/>
</p:remoteCommand>
</p:dialog>
</h:form>
</div>
</ui:define>
</ui:decorate>
</html>

JSF PrimeFaces / Ajax rendering to Datable fails to add items to the list

I am trying to user a form in 'panelGrid' to render values in a dataTable using <f:ajax>. However, when submitting using the <h:commandButton> the values sent are not displayed in the dataTable. I am not getting a stack or any console errors in the browsers.
This is the my xhtml (Simplified):
Product Catalog:
<p:tabView id="tabView" style="width: 65%" >
<p:tab id="books" title="Books">
<p:dataGrid var="book" value="#{saleBean.productList}" columns="3"
rows="9" paginator="true" paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink}
{LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="3,6,9">
<h:form id="product" >
<p:panel header="#{book.name}" style="text-align: center">
<h:panelGrid columns="1" style="width: 65%">
<!-- Add Book Images here -->
<h:outputText value="#{book.price}"/>
<h:outputLabel value="Dct (in dollars): " />
<h:inputText id="discount" value="#{saleBean.item.unit_discount}" style="width: 50%" />
<p:commandButton value="Add to Cart" update=":dataTableForm:sc"
action="#{saleBean.doAddItem}"/>
</h:panelGrid>
</p:panel>
</h:form>
</p:dataGrid>
</p:tab>
<p:tab id="arts" title="Art / Various">
<!-- Art Products to be added here -->
</p:tab>
<p:tab id="other" title="Other">
<!-- Various Products to be Added here -->
</p:tab>
</p:tabView>
<hr/>
<h1>Shopping Cart</h1>
<hr/>
<h:form id="dataTableForm">
<p:dataTable id="sc" value="#{saleBean.sd}" var="item" style="width: 60%">
<p:column>
<f:facet name="header">
<h:outputText value="Product"/>
</f:facet>
<h:outputText value="#{item.product_fk}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Quantity"/>
</f:facet>
<h:outputText value="#{item.quantity}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Unit Price"/>
</f:facet>
<h:outputText value="#{item.unit_Cost}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Unit Discount"/>
</f:facet>
<h:outputText value="#{item.unit_discount}"/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
This the bean (Simplified):
public String doAddItem()
{
item.setUnit_Cost(product.getPrice());
item.setProduct_fk(product);
item.setQuantity(1);
sd.add(item);
return "productCatalog";
}
According to PrimeFaces documentation :
http://www.primefaces.org/docs/vdl/3.4/primefaces-p/commandButton.html
Your actionListener="#{saleBean.doAddItem}" must use a function corresponding to that :
public void doAddItem(ActionListener event)
{
// do your stuff
}
To use action here is an example :
action="#{saleBean.doAddItem}"
public String doAddItem(void)
{
item.setUnit_Cost(product.getPrice());
item.setProduct_fk(product);
item.setQuantity(1);
sd.add(item);
return "productCatalog";
}
Try to use only pf components when you can eg p:datatable. Replace the button with a p:commandButton and use process and update instead of f:ajax.
Also maybe it will by better to include the p:datatable in the form too.

Resources