0

我正在尝试使用单元格编辑来实现 primefaces 数据表。类似于此处实现的内容:

http://www.primefaces.org/showcase/ui/datatableCellEditing.jsf

所以这是我的 jsf 数据表代码:

<h:form>
<p:growl id="messages" showDetail="true"/>
<p:panel id="dataPanel">                
    <p:dataTable 
    id="imagesDataTable"
    var="cRImageData" 
    value="#{syncCenterBean.cRImageDataList}"
    widgetVar="imagesTable" 
    paginator="true"
    sortMode="multiple"
    rows="10"
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="10,15,20,30" 
    paginatorAlwaysVisible="false"
            editable="true"
            editMode="cell">

        <p:ajax event="cellEdit" listener="#{syncCenterBean.onCellEdit}" update=":form:messages" />
        <p:column sortBy="#{cRImageData.imId}" headerText="ID" style="width:100px;text-align:center;">
            <h:outputText value="#{cRImageData.imId}" />
        </p:column>

        <p:column headerText="Image Name" style="width:180px;text-align:center;">
            <h:outputText value="#{cRImageData.imName}" />
        </p:column>

        <p:column headerText="Image Type" style="width:170px;text-align:center;">
             <p:cellEditor>  
                <f:facet name="output">
                    <h:outputText value="#{cRImageData.imType}" />
                </f:facet>  
                <f:facet name="input">  
                    <h:selectOneMenu value="#{syncCenterBean.cRImageTypeList}" style="width:100%">  
                        <f:selectItems value="#{syncCenterBean.cRImageTypeList}" var="imTypeId" itemLabel="#{imTypeId}" itemValue="#{imTypeId}" />  
                    </h:selectOneMenu>  
                </f:facet>  
            </p:cellEditor>
        </p:column>
        ...

这是我的后豆的代码:

@ManagedBean(name = "syncCenterBean")
@RequestScoped
public class SyncCenterBean implements Serializable {

    ....

    List<CRImageData> cRImageDataList;
    List<CRImageType> cRImageTypeList;

    @SuppressWarnings("unchecked")
    public SyncCenterBean(){

        cRImageTypeList = getImageTypesDB(); //returns a populated list of objects
        cRImageDataList = getImageDataDB(); //returns a populated list of objects
    }
    ...
    public void onCellEdit(CellEditEvent event) {  
    Object oldValue = event.getOldValue();  
    Object newValue = event.getNewValue();  

    if(newValue != null && !newValue.equals(oldValue)) {  
        FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);  
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  
}

但是当我尝试加载视图时,我得到:

Caused by: javax.faces.view.facelets.TagException: .... Event:cellEdit is not supported. 

在线的:

<p:ajax event="cellEdit" listener="#{syncCenterBean.onCellEdit}" update=":form:messages" />
4

1 回答 1

0

您应该为此事件编辑数据表

<p:datatable editable="true" editMode="cell" />
于 2013-04-15T13:52:35.463 回答