我有一个带有incell编辑的数据表,可以正确显示记录但是当我尝试编辑一行时,不会反映出这种变化。以下是xhtml代码:
<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>
以下是托管bean函数:
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){
}
}
或者我也尝试过:
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>
答案 0 :(得分:1)
最重要的部分是缺少数据表标记。
确保“editable”属性设置为true。我认为这个属性是在3.2版本中发明的,使许多onld数据表不可编辑。
答案 1 :(得分:0)
尝试使用h:inputText
代替p:inputText
。