事件:cellEdit不支持primefaces数据表单元格编辑

时间:2013-04-15 13:28:14

标签: jsf primefaces

我正在尝试使用单元格编辑来实现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" />

1 个答案:

答案 0 :(得分:0)

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

<p:datatable editable="true" editMode="cell" />