PrimeFaces Datatable editable row is not working - primefaces

I had implement editable p:datatable. After I click on the edit button and change the value, the Edit and Cancel button is not working, and the row just keep open to edit. May I know any mistake I am facing?
The code is
<p:panel>
<p:messages id="tableMessages" autoUpdate="true" closable="true" />
<p:dataTable value="#{bean.dataList}" var="data"
id="table" editable="true">
<p:ajax event="rowEdit" listener="#{bean.onRowEdit}"/>
<p:ajax event="rowEditCancel" listener="#{bean.onRowCancel}"/>
<p:column>
<f:facet name="header">
<h:outputLabel value="ID" />
</f:facet>
<h:outputText value="#{data.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Name" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{data.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="editName" value="#{data.name}">
<f:validateLength minimum="3" maximum="30" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Gender" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{data.gender}" />
</f:facet>
<f:facet name="input">
<p:inputText id="editGender" value="#{data.gender}">
<f:validateLength minimum="3" maximum="30" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Edit" />
</f:facet>
<p:rowEditor />
</p:column>
</p:dataTable>
</p:panel>

Related

When i click on dataexporter, it validates input fields instead of exporting datatable

I am writing code for adding and viewing vendor. But the issue is that, i added a dataexporter to export the table in different format. When i click on the dataexporter, it validates inpuut fields instead of exporting the datatable. see code below,
<h:panelGrid columns="6">
<p:outputLabel value="Vendor Name: " for="vname"/>
<p:inputText id="vname" required="true" value="#{bank.vendor_name}" />
<p:message for="vname"/>
<p:outputLabel value="Vendor Bank: " for="bank"/>
<p:selectOneMenu id="bank" value="#{bank.bankmode.bankName}" required="true" requiredMessage="Bank required">
<f:selectItem itemLabel="--Select Bank--" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{bank.bankmodel}"
var="singlevalue"
itemLabel="#{singlevalue.bankName}"
itemValue="#{singlevalue.bankName}"/>
</p:selectOneMenu>
<p:message for="bank"/>
<p:outputLabel value="Vendor Account Number: " for="anum"/>
<p:inputText id="anum" required="true" value="#{bank.vendor_acct}" requiredMessage="Account Number required" />
<p:message for="anum"/>
<p:outputLabel value="Vendor Contact Address: " for="adress"/>
<p:inputTextarea id="adress" required="true" value="#{bank.vendor_address}" requiredMessage="Contact Address required" />
<p:message for="adress"/>
<p:outputLabel value="Vendor Email Address: " for="email"/>
<p:inputText id="email" required="true" label="email" size="40"
requiredMessage="Please enter your email address."
validatorMessage="Invalid email format"
value="#{bank.vendor_email}">
<f:validateRegex
pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
</p:inputText>
<p:message for="email" />
<p:outputLabel value="Vendor Phone Number " for="pnum"/>
<p:inputText id="pnum" required="true" value="#{bank.vendor_phone}" requiredMessage="Phone number required" />
<p:message for="pnum"/>
<p:commandButton value="save" process="#this vname,bank,anum,adress,email,pnum" update=":templateForm:growl,singleTB,ven" actionListener="#{bank.insertData}" />
</h:panelGrid>
<p:dataTable var="ven_tab" id="singleTB"
value="#{bank.vendorList}"
rowKey="#{ven_tab.id}"
selection="#{bank.selectedList}" selectionMode="single"
rows="10"
editable="true"
paginatorTemplate="{CurrentPageReport}
{FirstPageLink} {PreviousPageLink}
{PageLinks} {NextPageLink} {LastPageLink} "
paginator="true" style="margin-bottom:20px"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowEdit" listener="#{bank.onRowEdit}" update=":templateForm:growl" />
<p:ajax event="rowEditCancel" listener="#{bank.onRowCancel}" update=":templateForm:growl" />
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Id"/>
</f:facet>
<h:outputText value="#{ven_tab.vendorId}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Name"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{ven_tab.vendorName}"/></f:facet>
<f:facet name="input"><p:inputText value="#{ven_tab.vendorName}" required="true" requiredMessage="Name is required" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Phone Number"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{ven_tab.vendorPnum}"/></f:facet>
<f:facet name="input"><p:inputText value="#{ven_tab.vendorPnum}" required="true" requiredMessage="Phone is required" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Email"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{ven_tab.vendorEmail}"/></f:facet>
<f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorEmail}" requiredMessage="Email is required" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Contact Address"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{ven_tab.vendorContact}"/></f:facet>
<f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorContact}" requiredMessage="Contact is required" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Bank"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{ven_tab.vendorBank}"/></f:facet>
<f:facet name="input">
<p:selectOneMenu id="bank" style="width:100%" value="#{ven_tab.vendorBank}" required="true" requiredMessage="Bank required">
<f:selectItem itemLabel="--Select Bank--" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{bank.bankmodel}"
var="singlevalue"
itemLabel="#{singlevalue.bankName}"
itemValue="#{singlevalue.bankName}"/>
</p:selectOneMenu></f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Vendor Account Number"/>
</f:facet>
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{ven_tab.vendorAcct}"/></f:facet>
<f:facet name="input"><p:inputText required="true" value="#{ven_tab.vendorAcct}" requiredMessage="Account is required" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
<h3>Export Page Data Only</h3>
<p:contextMenu for="singleTB" rendered="#{bank.status}" >
<p:menuitem value="Delete" process="#this singleTB" update=":templateForm:growl,singleTB" icon="ui-icon-close" actionListener="#{bank.deleteCar}"/>
</p:contextMenu>
<h:commandLink>
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="singleTB" fileName="report" pageOnly="true"/>
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/pdf.png" />
<p:dataExporter type="pdf" target="singleTB" fileName="report" pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/csv.png" />
<p:dataExporter type="csv" target="singleTB" fileName="report" pageOnly="true" />
</h:commandLink>
<h:commandLink>
<p:graphicImage value="/images/xml.png" />
<p:dataExporter type="xml" target="singleTB" fileName="report" pageOnly="true" />
</h:commandLink>
Please assist. I have been trying to fix this for sometime now and keep getting thesame result. Thanks
JSF has 6 life cycle phases. One of them is the Process Validation phase. In this phase, the validation of input components (e.g., input fields) takes place. In your case, you do not want the validation to takes place. So what you do is adding an immediate attribute to your commandlink component as:
<h:commandLink immediate="true">
<p:graphicImage value="/images/excel.png" />
<p:dataExporter type="xls" target="singleTB" fileName="report" pageOnly="true"/>
</h:commandLink>
With this setting all the life cycle phases after the Apply Request Values until the Render Response phase will be skipped.

Exclude button on the dataTable when exporting to excel file in PrimeFaces

<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="#{bundle.ListDriverTitle}"></h:outputText>
</ui:define>
<ui:define name="body">
<h:form id="driverForm">
<h:panelGrid id="messagePanel" >
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGrid>
<h:panelGrid >
<p:dataTable value="#{driverController.items}" lazy="true" selectionMode="single" paginator="true" rows="10" paginatorPosition="bottom" var="item" id="itemTable" rowKey="#{item.id}" styleClass="ui-datatable-hor-scroll">
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_id}"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_surname}"/>
</f:facet>
<h:outputText value="#{item.surname}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_names}"/>
</f:facet>
<h:outputText value="#{item.names}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_idNumber}"/>
</f:facet>
<h:outputText value="#{item.idNumber}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_driverCode}"/>
</f:facet>
<h:outputText value="#{item.driverCode}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_active}"/>
</f:facet>
<h:outputText value="#{item.active}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_type}"/>
</f:facet>
<h:outputText value="#{item.type}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_cellNumber}"/>
</f:facet>
<h:outputText value="#{item.cellNumber}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_createdDate}"/>
</f:facet>
<h:outputText value="#{item.createdDate}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListDriverTitle_whs}"/>
</f:facet>
<h:outputText value="#{item.whs.name}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<p:commandButton action="#{driverController.prepareView}" value="#{bundle.ListDriverViewLink}" ajax="false" immediate="false">
<f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}"/>
</p:commandButton>
<h:outputText value=" "/>
<p:commandButton action="#{driverController.prepareEdit}" value="#{bundle.ListDriverEditLink}" ajax="false" immediate="false">
<f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}" />
</p:commandButton>
<h:outputText value=" "/>
<p:commandButton action="#{driverController.destroy}" value="Delete" ajax="false" immediate="false">
<f:setPropertyActionListener target="#{driverController.selectedDriver}" value="#{item}"/>
</p:commandButton>
</p:column>
</p:dataTable>
</h:panelGrid>
<br />
<p:commandButton action="#{driverController.prepareCreate}" value="#{bundle.ListDriverCreateLink}" ajax="false"/>
<p:menuButton value="Download Documents">
<p:menuitem immediate="true" process="#none" ajax="false">
<h:commandLink target="_blank">
<img src="#{resource['images/excel-icon.png']}" style="border: none; width: 15px; height: 15px;"/>
<p:dataExporter type="xls" target="itemTable" fileName="DriversList" pageOnly="true"/>
<span>Current page</span>
</h:commandLink>
</p:menuitem>
<p:menuitem immediate="true" process="#none" ajax="false">
<h:commandLink target="_blank">
<img src="#{resource['images/excel-icon.png']}" style="border: none; width: 15px; height: 15px;"/>
<p:dataExporter type="xls" target="itemTable"fileName="DriversList" p/>
<span>All pages</span>
</h:commandLink>
</p:menuitem>
</p:menuButton>
</h:form>
</ui:define>
</ui:composition>
When I download an excel file, the buttons from the table are also downloaded. What can I do to exclude them.
If you need more explanation please feel free to ask me. I need the best solution. Thank you
You can exclude columns, which should not be exported by using:
<p:column exportable="false">

How to create a List in a Session and submit before

I need create a list of Phones in na and submit before.
In my firt try the object came empty and the list shows a list of null objets
<h:panelGrid id="gridPhone" columns="5">
<h:outputText value="Numero:" />
<h:inputText value="#{profileMB.phone.number}" size="10"/>
<h:outputText value="Tipo" />
<p:selectOneMenu id="selPhoneType" value="#{profileMB.phone.type}" >
<f:selectItems var="phoneType" value="#{profileMB.listPhoneTypes}" itemLabel="#{phoneType.description}" itemValue="#{phoneType}" />
</p:selectOneMenu>
<p:commandButton action="#{profileMB.addPhoneOnList()}" immediate="true" value="adicionar" update=":messageGrowl listPhones"/>
<f:facet name="footer">
<h:panelGroup style="display:block; text-align:center;width: 300px;">
<p:selectOneListbox id="listPhones" >
<f:selectItems var="phones" value="#{profileMB.phones}" itemLabel="#{phones.number}" />
</p:selectOneListbox>
</h:panelGroup>
</f:facet>
<p:ajaxStatus style="display:block;margin-bottom:2em;height:24px;">
<f:facet name="default">
<h:outputText value="" />
</f:facet>
<f:facet name="start">
<p:graphicImage name="/images/spiffygif_30x30.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
in my second try the object was filled but the Litt does update
<h:panelGrid id="gridPhone" columns="5">
<h:outputText value="Numero:" />
<h:inputText value="#{profileMB.phone.number}" size="10"/>
<h:outputText value="Tipo" />
<p:selectOneMenu id="selPhoneType" value="#{profileMB.phone.type}" >
<f:selectItems var="phoneType" value="#{profileMB.listPhoneTypes}" itemLabel="#{phoneType.description}" itemValue="#{phoneType}" />
</p:selectOneMenu>
<p:commandButton action="#{profileMB.addPhoneOnList()}" partialSubmit="true" process="gridPhone, listPhones" value="adicionar" update=":messageGrowl"/>
<f:facet name="footer">
<h:panelGroup style="display:block; text-align:center;width: 300px;">
<p:selectOneListbox id="listPhones" >
<f:selectItems var="phones" value="#{profileMB.phones}" itemLabel="#{phones.number}" />
</p:selectOneListbox>
</h:panelGroup>
</f:facet>
<p:ajaxStatus style="display:block;margin-bottom:2em;height:24px;">
<f:facet name="default">
<h:outputText value="" />
</f:facet>
<f:facet name="start">
<p:graphicImage name="/images/spiffygif_30x30.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</h:panelGrid>
I have try sereval forms but dont work
:(

p:cellEditor inside a p:column

I would like to have something like this, a column and inside this column I can have one editor based on another configuration, but when I have tried this code p:column doesnt render the p:cellEditor.
<p:column headerText="Tipo">
<ui:fragment rendered="#{_field.isType('String')}">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{_field.sValue}" rendered="#{_field.isType('String')}" /></f:facet>
<f:facet name="input"> <p:inputText value="#{_field.sValue}" style="width:100%" rendered="#{_field.isType('String')}" /></f:facet>
</p:cellEditor>
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Integer')}">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{_field.iValue}" rendered="#{_field.isType('Integer')}" /> </f:facet>
<f:facet name="input"> <p:inputText value="#{_field.iValue}" rendered="#{_field.isType('Integer')}" style="width:100%" /></f:facet>
</p:cellEditor>
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Ativo')}">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{_field.aValue.nome}" rendered="#{_field.isType('Ativo')}" /></f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{_field.aValue}" style="width:100%" rendered="#{_field.isType('Ativo')}">
<f:selectItems value="#{ativoBean.listaAtivos}" var="_asset" itemLabel="#{_asset.nome}" itemValue="#{_asset}" />
<f:converter converterId="ativoConverter" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</ui:fragment>
</p:column>
It works
<p:column headerText="Tipo">
<p:cellEditor>
<f:facet name="output">
<ui:fragment rendered="#{_field.isType('String')}">
<h:outputText value="#{_field.sValue}" rendered="#{_field.isType('String')}" />
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Integer')}">
<h:outputText value="#{_field.iValue}" rendered="#{_field.isType('Integer')}" />
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Ativo')}">
<h:outputText value="#{_field.aValue.nome}" rendered="#{_field.isType('Ativo')}" />
</ui:fragment>
</f:facet>
<f:facet name="input">
<ui:fragment rendered="#{_field.isType('String')}">
<p:inputText value="#{_field.sValue}" style="width:100%" rendered="#{_field.isType('String')}" />
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Integer')}">
<p:inputText value="#{_field.iValue}" rendered="#{_field.isType('Integer')}" style="width:100%" />
</ui:fragment>
<ui:fragment rendered="#{_field.isType('Ativo')}">
<p:selectOneMenu value="#{_field.aValue}" style="width:100%" rendered="#{_field.isType('Ativo')}">
<f:selectItems value="#{ativoBean.listaAtivos}" var="_asset" itemLabel="#{_asset.nome}" itemValue="#{_asset}" />
<f:converter converterId="ativoConverter" />
</p:selectOneMenu>
</ui:fragment>
</f:facet>
</p:cellEditor>

can"t refresh form or page after row update in editable p:dataTable

I have a strange behavior with rowEdit of dataTable. when I modify a row of the table the row is modified successfully, but I can not refresh the form or the page, I tried the solution
<p:ajax event="rowEdit" update="#form" listener="#{pecBean.onEdit}"/>
result: the form is not completely displayed. then I tried
<p:ajax event="rowEdit" update="#all" listener="#{pecBean.onEdit}"/>
result: the page is not fully refreshed
below the full source code.
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<title>(For validation only)</title>
<link href="./css/styles.css" rel="stylesheet" type="text/css" />
</h:head>
<body class="bodyMain">
<composite:interface />
<composite:implementation>
<h:form id="form" prependId="false">
<h:panelGrid>
<h:panelGrid id="recapActes">
<h:panelGrid>
<p:panel id="recapGlobale" header="Récap globale Prise en charge">
<h:panelGrid>
<h:panelGrid columns="4">
<h:outputText styleClass="lib" value="Total PEC Base" />
<h:outputText styleClass="valeur"
value="#{pecBean.recapPec.totalRemboursementBase}">
</h:outputText>
<h:outputText styleClass="lib" value="Total PEC complémentaire" />
<h:outputText styleClass="valeur"
value="#{pecBean.recapPec.totalRemboursementComplementaire}">
</h:outputText>
</h:panelGrid>
</h:panelGrid>
</p:panel>
</h:panelGrid>
<h:panelGrid>
<p:dataTable sortBy="#{am.acte.categorieActe.code}"
editable="true" rowKey="#{am.idActePec}"
value="#{pecBean.actesPec}" var="am">
<p:ajax event="rowEdit" update="#all"
listener="#{pecBean.onEdit}" />
<p:column>
<f:facet name="header">Code acte</f:facet>
#{am.acte.code}
</p:column>
<p:column styleClass="bla">
<f:facet name="header">Lib acte</f:facet>
#{am.acte.libelle}
</p:column>
<p:column>
<f:facet name="header">Coefficient</f:facet>
#{am.coefficientActe}
</p:column>
<p:column>
<f:facet name="header">Quantité souscrite</f:facet>
#{am.quantiteActeSouscrit}
</p:column>
<p:column>
<f:facet name="header">Quantité accordée</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{am.quantiteActeAccorde}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{am.quantiteActeAccorde}" required="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">Observation</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{am.observation}" />
</f:facet>
<f:facet name="input">
<h:inputTextarea value="#{am.observation}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">Pec Base</f:facet>
<h:outputText value="#{am.rembBase}">
</h:outputText>
</p:column>
<p:column style="text-align:right">
<f:facet name="header">Pec Compl</f:facet>
<h:outputText
value="#{am.rembComplementaire}">
</h:outputText>
</p:column>
<p:column>
<p:rowEditor />
</p:column>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:panelGrid>
</h:form>
</composite:implementation>
</body>
</html>
thanks for any help.