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>