3

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>

4

2 回答 2

1

最重要的部分是缺少数据表标签。

确保“可编辑”属性设置为 true。我认为这个属性是在 3.2 版中发明的,这使得许多 onld 数据表不可编辑。

于 2012-05-12T14:45:13.140 回答
0

尝试使用h:inputText而不是p:inputText.

于 2012-10-29T22:38:52.217 回答