0

我想将ratedValue 设置为bean。当我在cellEditor 中添加值并单击保存按钮时,ratedValue 将变为null。

      <p:dataTable id="manager" var="item" value="#{employeedaBean.userList}"
                paginator="true" rows="10"
                paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                rowsPerPageTemplate="2,5,10,15" 
                editable="true" editMode="cell" widgetVar="carsTable"
                lazy="true" emptyMessage="No Customers found with given criteria"> 

          <f:facet name="header">  
          Employee 
          </f:facet>  

              <p:column headerText="Rated">  
              <p:cellEditor>  
              <f:facet name="output"><h:outputText value="#{item.ratedValue}" /></f:facet>  
              <f:facet name="input">  
                <p:selectOneMenu value="#{item.ratedValue}" style="width:100%">  
                    <f:selectItems value="#{employeedaBean.rateValueMany}"/>  
                </p:selectOneMenu>  
              </f:facet>  
              </p:cellEditor>  
              </p:column> 

  </p:dataTable>  
4

1 回答 1

1

您需要首先定义一个 ajax 侦听器:(在您的情况下,例如在标题部分下方)

<p:ajax event="rowEdit" listener="#{listener.onEdit}" update=":manager" />

然后,您需要定义:(您已经拥有 - rowEditor 或 cellEditor)

<p:column styleClass="admin-columns-text">
    <p:rowEditor/> or <p:cellEditor/>
</p:column>

然后在您的侦听器方法中,您可以检索新值,如下所示:

(如果您使用RowEditEvent

  public void onEdit(RowEditEvent event) {
    User userChanged = (User) event.getObject();
  }

(如果您使用CellEditEvent

  public void onEdit(CellEditEvent event) {
    User userOld = (User) event.getOldValue();
    User userNew = (User) event.getNewValue();
  }
于 2013-09-24T11:12:35.777 回答