I am getting an error message while trying to use PrimeFaces for my making each row editable. I was checking online many people are making use of this. However when I am trying to create a page with a report in which each row can be edited. I get error that Event:rowEdit is not supported. Can someone please point out my mistake or something I need to include in my XHTML file. Or If i'm doing things right at all.
This table has lot of data that's why I took this approach
Below is the additional information regarding my setup :
Glassfish v3
JPA2.1
PrimeFaces3.5 (i hve the jar included in my project's build path since other report pages are working to confirm primefaces is working)
EJB 3.1
Here is my XHTML code
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:p="http://primefaces.org/ui">
<f:metadata>
<f:viewParam name="userId" value="#{loginBean.username}"></f:viewParam>
</f:metadata>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link href="./css/PageLayout.css" rel="stylesheet" type="text/css" />
<title>Edit Lord of Data Entries</title>
</h:head>
<h:body>
<div style="background-color: #205a8c; width: auto; height: 60px">
<h3>Edit Lord Of Data</h3>
</div>
<div id="breadcrumb" align="left">
<h:form>
<p:breadCrumb>
<p:menuitem value="Home" url="home.jsf"></p:menuitem>
<p:menuitem value="Home" url="home.jsf"></p:menuitem>
<p:menuitem value="Users" url="reportUsers.jsf"></p:menuitem>
<p:menuitem value="Groups" url="reportGroups.jsf"></p:menuitem>
<p:menuitem value="User's Group" url="reportUserGroup.jsf"></p:menuitem>
</p:breadCrumb>
</h:form>
</div>
<h:form id="form">
<p:growl id="messages" showDetail="true"></p:growl>
<p:dataTable var="myReport"
value="#{lordOfDataAdminManagedBean.lodAdmin_list}" id="lodlist"
editable="true" paginator="true"
rows="500"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="500,1000,5000">
<f:facet name="header"> Lord Of Data Report</f:facet>
<p:ajax event="rowEdit"
listener="#{lordOfDataAdminManagedBean.onEditListener}"></p:ajax>
<p:ajax event="rowEditCancel"
listener="#{lordOfDataAdminManagedBean.onCancel}"></p:ajax>
<p:column>
<p:rowEditor></p:rowEditor>
</p:column>
<p:column headerText="Row Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.rowId}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.rowId}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Group Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.security}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.security}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.type}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.type}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Auto">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.auto}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.auto}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Access">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.access}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.access}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Comment">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.comment}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.comment}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD1 Domain">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD1Domain}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD1Domain}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD1 User">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD1User}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD1User}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD1 Mail">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD1Mail}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD1Mail}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD1 Display Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD1DisplayName}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD1DisplayName}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD1 Cost Center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD1CostCenter}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD1CostCenter}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD2 User">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD2User}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD2User}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD2 Mail">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD2Mail}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD2Mail}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD2 Display Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD2DisplayName}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD2DisplayName}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD2 Cost Center">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD2CostCenter}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD2CostCenter}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Domain1">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.domain1}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.domain1}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="RechteGruppe Read">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.rechteGruppeRead}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.rechteGruppeRead}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="AuthentifizierteBenutzer">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.authentifizierteBenutzer}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.authentifizierteBenutzer}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LOD2 Domain">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.LOD2Domain}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.LOD2Domain}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email Send Status">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.emailSendStatus}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.emailSendStatus}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email Feedback">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.emailFeedback}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.emailFeedback}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Comment1">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.comment1}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.comment1}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Comment2">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.comment2}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.comment2}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Comment 3">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.comment3}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.comment3}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Username">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.username}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.username}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Managed Bean Code snippet for handling Edit function
public void onEditListener(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Edited");
try {
Lodreport mydata = (Lodreport) event.getObject();
if (mydata == null) {
System.out.println("No data input found");
} else {
lODBR.updateReport(mydata);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
} catch (Exception e) {
}
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
Error Stack Trace
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.view.facelets.TagException: /editNewLODAdmin.xhtml #44,7 <p:ajax> Event:rowEdit is not supported.
at org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.applyAttachedObject(AjaxBehaviorHandler.java:149)
at org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.apply(AjaxBehaviorHandler.java:127)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
at com.sun.faces.facelets.tag.jsf.ComponentTagHandlerDelegateImpl.apply(ComponentTagHandlerDelegateImpl.java:184)
at javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
at com.sun.faces.application.view.StateManagementStrategyImpl.restoreView(StateManagementStrategyImpl.java:223)
at com.sun.faces.application.StateManagerImpl.restoreView(StateManagerImpl.java:188)
at com.sun.faces.application.view.ViewHandlingStrategy.restoreView(ViewHandlingStrategy.java:123)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.restoreView(FaceletViewHandlingStrategy.java:453)
at com.sun.faces.application.view.MultiViewHandler.restoreView(MultiViewHandler.java:148)
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:192)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
It's not working because
You technically haven't added row editing support to your table, you're editing a cell. Add a <p:rowEditor/> to your table to hook into the rowEdit event
Your table, it's not a real table. The <p:dataTable/> tag doesn't actually wrap the <p:column/> or anything else
What you should have:
<p:dataTable var="myReport" value="#{lordOfDataAdminManagedBean.lodAdmin_list}" id="lodlist" editable="true">
<f:facet name="header"> Lord Of Data Report</f:facet>
<p:ajax event="rowEdit"
listener="#{lordOfDataAdminManagedBean.onEditListener}"
></p:ajax>
<p:ajax event="rowEditCancel"
listener="#{lordOfDataAdminManagedBean.onCancel}"
></p:ajax>
<p:column headerText="Row Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.rowId}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.rowId}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:rowEditor />
</p:column>
</p:dataTable>
I see:
<p:dataTable var="myReport"
value="#{lordOfDataAdminManagedBean.lodAdmin_list}" id="lodlist"
editable="true"></p:dataTable>
<f:facet name="header"> Lord Of Data Report</f:facet>
<p:ajax event="rowEdit"
listener="#{lordOfDataAdminManagedBean.onEditListener}"
></p:ajax>
<p:ajax event="rowEditCancel"
listener="#{lordOfDataAdminManagedBean.onCancel}"
></p:ajax>
<p:column headerText="Row Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.rowId}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.rowId}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
you have to try:
<p:dataTable var="myReport"
value="#{lordOfDataAdminManagedBean.lodAdmin_list}" id="lodlist"
editable="true">
<f:facet name="header"> Lord Of Data Report</f:facet>
<p:ajax event="rowEdit"
listener="#{lordOfDataAdminManagedBean.onEditListener}"
></p:ajax>
<p:ajax event="rowEditCancel"
listener="#{lordOfDataAdminManagedBean.onCancel}"
></p:ajax>
<p:column headerText="Row Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{myReport.rowId}"></h:outputText>
</f:facet>
<f:facet name="input">
<p:inputText value="#{myReport.rowId}"></p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
Related
So I am trying to use a PrimeFaces data table to set data to a list as follows;
<h:form id="frmSalarySupplement">
<p:panel>
<p:dataTable id="tblSalarySupplement"
value="#{salSupplementMB.dataListFromDB}"
var="salSupp"
rowIndexVar="rowSn"
scrollable="true"
rows="10"
paginator="true"
editable="true"
editMode="cell"
rowsPerPageTemplate="10,20,50,100">
<p:ajax event="cellEdit"
listener="#{salSupplementMB.onCellEdit}"
update="#this" />
<p:column headerText="#" escape="false"
style="white-space:pre-line;
word-break:break-all;
width:20px;
text-align:center;">
<h:outputText value="#{rowSn+1}" />
</p:column>
<p:column headerText="Name"
style="white-space:pre-line;
word-break:break-all;
width:250px;">
<h:outputText value="#{salSupp.empId.name}" />
</p:column>
<p:column headerText="Designation"
style="white-space:pre-line;
word-break:break-all;
width:150px;">
<h:outputText value="#{salSupp.empId.designation.designationName}" />
</p:column>
<p:column headerText="Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.allowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.allowance}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Special
Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.specialAllowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.specialAllowance}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Transport
Allowance"
style="white-space:pre-line;
word-break:break-all;
width:100px;">
<p:cellEditor>
<f:facet name="input">
<h:inputText value="#{salSupp.transportAllowance}"
style="width:100%" />
</f:facet>
<f:facet name="output">
<h:outputText value="#{salSupp.transportAllowance}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
So I want to be able to save the data I have edited on the cell to set it on the list. When I do the following, I don't get an updated value.
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
}
Can someone suggest what shall I do with it?
Update
Also, can anyone tell me why my table loads multiple times when I edit the value? Maybe that's what's giving me the problem.
I have a problem in datatable when adding a new line:
I want to add a blank line, but if I click on the button it adds a line but component remains.
<p:selectCheckboxMenu> contains old value.
That is to say value of <p:selectCheckboxMenu> preserves the value of the previous line
<p:dataTable value="#{solotionManager.customers}"
id="table" var="o"
widgetVar="50"
style="width: 100%;"
editable="true"
scrollHeight="330"
styleClass="datatable">
<p:ajax event="rowEdit" listener="#{customerBeansController2.onEdit}" update=":form1:table" process="#this"/>
<f:facet name="header">
Order List
</f:facet>
<p:ajax event="rowEditCancel" listener="#{customerBeansController2.onCancel}" update=":form1:messages"/>
<p:column>
<f:facet name="header" >
<h:outputText value="ID customer" style="width:100%"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.id}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.id}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="firstName"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.firstName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.firstName}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="lastName"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{o.lastName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{o.lastName}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="SelectManyMenu" style="width:100%"/>
</f:facet>
<p:cellEditor>
<f:facet name="input">
<p:selectCheckboxMenu value="#{solotionManager.choice}" label="Phone" converter="entrantConverter">
<f:selectItems value="#{solotionManager.listeChoice}" var="c" itemValue="#{c}" itemLabel="#{c}"/>
</p:selectCheckboxMenu >
</f:facet>
<f:facet name="output">
<p:selectCheckboxMenu value="#{solotionManager.choice}" label="Phone" converter="entrantConverter">
<f:selectItems value="#{solotionManager.listeChoice}" var="c" itemValue="#{c}" itemLabel="#{c}"/>
</p:selectCheckboxMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor/>
</p:column>
</p:dataTable>
public String newLine(javax.faces.event.ActionEvent actionEvent) {
this.customers.add(this.custom1);
this.custom1=new Customer();
return null;
}
the code for the button that adds the line:
<p:commandButton value="add row" actionListener="#{solotionManager.newLine}" update="table" oncomplete="addRowOnComplete()"/>
Function javascript addRowOncomplete :
<script type="text/javascript">
function addRowOnComplete() {
jQuery('.ui-datatable-data tr td').last().find('span.ui-icon-pencil').each(function(){jQuery(this).click();});
}
</script>
I have a datatable element where I use a rowEditor. Additionally it is possible to add a new record which is implemented as inputFields in the footer of the table. All elements are validated. The problem is, that when a user hits the rowEditor the validation complains that the values for a new record are not set.
How can I avoid that the new record fields are being validated when the rowEditor is clicked?
I fiddled around a bit with proccess & immediate on the ajax events but I'm not able to figure this out. Is this possible and if yes, how? I'm thankful for help.
<p:dataTable var="contact"
value="#{data.activeCustomer.contacts.toArray()}"
id="contactsTable"
emptyMessage="#{ivy.cms.co('/Translations/Administration/noRecordsFoundSearch')}"
editable="true">
<p:ajax event="rowEdit" listener="#{logic.onEdit(contact)}" />
<p:ajax event="rowEditCancel" listener="#{logic.onCancel}" />
<f:facet name="header">
#{ivy.cms.co('/Translations/Administration/Contacts/labelContacts')}
</f:facet>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/prename')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.prename}" />
</f:facet>
<f:facet name="input">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPrename')}"
value="#{contact.prename}"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPrename')}"
value="#{data.contactPrename}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/surname')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.surname}" />
</f:facet>
<f:facet name="input">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterSurname')}"
value="#{contact.surname}"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterSurname')}"
value="#{data.contactSurname}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/phone')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.phone}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{contact.phone}"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPhone')}"
required="true"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPhone')}"
required="true" value="#{data.contactPhone}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/email')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.email}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{contact.email}" required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterEmail')}">
<f:validator validatorId="EmailValidator" />
</p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterEmail')}"
value="#{data.contactEmail}">
<f:validator validatorId="EmailValidator" />
</p:inputText>
</f:facet>
</p:column>
<p:column style="width: 6%"
headerText="#{ivy.cms.co('/Translations/CustomerAdministration/actionsColumnTitle')}">
<p:rowEditor />
<p:commandLink styleClass="ui-icon ui-icon-trash"
actionListener="#{logic.deleteContact(contact)}"
icon="ui-icon-trash" update=":#{p:component('contactForm')}"
immediate="true" />
<f:facet name="footer">
<h:commandButton
value="#{ivy.cms.co('/Translations/Administration/Contacts/ButtonAddContact')}"
actionListener="#{logic.addContact}" />
</f:facet>
</p:column>
</p:dataTable>
</h:form>
#Named(value = "viewtable")
#ManagedBean
#ViewScoped
public final class viewtable implements Serializable {
ArrayList<viewbean> dlist = new ArrayList<viewbean>();
ArrayList<Master> mlist = new ArrayList<Master>();
public ArrayList<viewbean> getDlist() {
return dlist;
}
public viewtable() {
get();
}
public void get() {
try
{
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jdbc/mydsn");
Connection con = ds.getConnection();
PreparedStatement ps=con.prepareStatement("select * from master");
ResultSet rs=ps.executeQuery();
while(rs.next())
{
dlist.add(new viewbean(rs.getString(1), rs.getString(2),rs.getString(3),rs.getString(4),rs.getDate(5), rs.getString(6), rs.getBytes(7), rs.getString(8),rs.getString(9),rs.getString(10),rs.getString(11),rs.getDate(12),rs.getDate(13),rs.getString(14),rs.getString(15), rs.getString(16)));
}
}catch(Exception ex)
{
System.out.println("Conncetion pool db error-> "+ex);
}
}
public void onEdit(RowEditEvent event) {
}
}
The above code didn't update the data in the database in the get() method I've done any error and how to connect with the database using PrimeFaces.
I used a managed bean for save details from the database as a list called mlist.
JSF:
<h:form id="dtform">
<p:growl showDetail="true" id="mess"/>
<p:dataTable id="dt1" scrollable="true" scrollWidth="700" var="mas" value="#{viewtable.dlist}" editable="true">
<f:facet name="header">
Edit Here
</f:facet>
<p:column headerText="Regno" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.regno}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.regno}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Rollno" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.rollno}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.rollno}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Firstname" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.fname}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.fname}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Lastname" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.lname}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.lname}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="D.O.B" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.dob}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.dob}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.address}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.address}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Avatar" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.avatar}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.avatar}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.email}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.email}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Phno" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.phno}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.phno}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Dept" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.dept}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.dept}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Year" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.year}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.year}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Start" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.inidate}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.inidate}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="End" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.enddate}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.enddate}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Remarks" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.remarks}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.remarks}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Delivery" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.delivery}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.delivery}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Message" width="100">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{mas.messdelivery}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{mas.messdelivery}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options" width="100">
<p:rowEditor/>
</p:column>
<p:ajax event="rowEdit" listener="#{viewtable.onEdit}" update=":dtform:mess"/>
</p:dataTable>
</h:form>
I assume you have configured hibernate in your environment, and mapped your database to an entity class. you can update the records accordingly.
You can access the rows and update the records like :
public void onEdit(RowEditEvent event) {
YourHibernateEntity yourEntity = (YourHibernateEntity ) event.getObject());
SessionFactory sessFact = new AnnotationConfiguration().configure().buildSessionFactory();
Session sess = sessFact.openSession();
Transaction tran = sess.beginTransaction();
sess.update(yourEntity );
tran.commit();
}
I have a datatable with incell editing which displays the records correctly but when I try to edit a row, the change is not reflected. Following is the xhtml code:
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.companyName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{scrip.companyName}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Exchange">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.exchange}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu style="width: 150px" value="#{manageScrip.exchange}">
<f:selectItem itemLabel="nse" itemValue="nse"/>
<f:selectItem itemLabel="bse" itemValue="bse"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Brokerage Charge">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.brokerageCharge}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{scrip.brokerageCharge}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
Following is the managed bean function:
public void updateScrip()
{
try{
Integer i=(Integer)dt.getRowKey();
String str=i.toString();
sc=(ScripMaster) dt.getRowData(str);
scripSymbol=sc.getScripSymbol();
exchange=sc.getExchange();
companyName=sc.getCompanyName();
updateScrip(i, scripSymbol, companyName, exchange,);
}catch(Exception ex){
}
}
Alternatively I also tried:
public void updateScrip(RowEditEvent e)
{
try{
sc=(ScripMaster) e.getObject();
scripSymbol=sc.getScripSymbol();
exchange=sc.getExchange();
companyName=sc.getCompanyName();
Integer i=sc.getScripID();
updateScrip(i, scripSymbol, companyName, exchange);
}catch(Exception ex){
}
}
<?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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form id="frm">
<p:commandLink action="/adminpages/addScrip" value="add scrip" ajax="false"/>
<p:dataTable editable="true" var="scrip" value="#{manageScrip.scripList}" binding="#{manageScrip.dt}" rowKey="#{scrip.scripID}" id="dt">
<p:ajax event="rowEdit" listener="#{manageScrip.updateScrip}" update="#this"/>
<p:column headerText="Scrip Symbol">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.scripSymbol}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{scrip.scripSymbol}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Company Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.companyName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{scrip.companyName}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Exchange">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.exchange}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu style="width: 150px" value="#{manageScrip.exchange}">
<f:selectItem itemLabel="nse" itemValue="nse"/>
<f:selectItem itemLabel="bse" itemValue="bse"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Brokerage Charge">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{scrip.brokerageCharge}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{scrip.brokerageCharge}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Options">
<p:rowEditor/>
</p:column>
</p:dataTable>
</h:form>
</h:body>
The most important part is missing the datatable tag.
Make sure the "editable" attribute is set to true. This attribute was invented in version 3.2 i think, making many onld datatables not editable.
Try using h:inputText instead of p:inputText.