简体   繁体   English

primefaces 3.2数据表incell编辑不起作用

[英]primefaces 3.2 datatable incell editing not working

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. 我有一个带有incell编辑的数据表,它可以正确显示记录但是当我尝试编辑一行时,不会反映出这种变化。 Following is the xhtml code: 以下是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>

Following is the managed bean function: 以下是托管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){

        }
}

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. 确保“editable”属性设置为true。 This attribute was invented in version 3.2 i think, making many onld datatables not editable. 我认为这个属性是在3.2版本中发明的,使许多onld数据表不可编辑。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM