使用JSF中呈现后,Primefaces数据表无法使用已编辑的值进行更新

时间:2015-05-21 06:52:43

标签: ajax jsf primefaces

单击命令按钮时,我将primefaces中数据表的呈现属性设置为true。数据表是可编辑的并且包含在面板内。

渲染工作正常当我点击命令按钮时,表格会显示,值正在编辑,但表格没有保留新的编辑值。

我认为用p:ajax标签写的函数没有被调用。 请有人帮忙......

我用Google搜索并发现要使用Ajax,应始终呈现UI,但我的要求是最初隐藏表。

P.S:当从桌子上移除renedred时,一切正常。 提前谢谢。

下面是我的代码

<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
  <p:commandButton value="Enter" update="panel1" icon="ui-icon-check"  actionListener="#{step1Bean.onClick}"/>

 <h:panelGrid id="panel1" columns="1" cellpadding="5">

  <p:dataTable id="pan1tab1" rendered="#{step1Bean.showPanel1}" var="car" value="#{dtEditView.cars2}" editable="true" editMode="cell"    widgetVar="cellCars" tableStyle="width:43%">

  <p:ajax event="cellEdit" listener="#{dtEditView.onCellEdit}"  update=":form:msgs"  />

   <p:column headerText="Id" id="col1">

          <p:cellEditor>
              <f:facet name="output"><h:outputText value="#{car.prodLine}"  /></f:facet>
              <f:facet name="input"><p:inputText id="modelInput" value="#{car.prodLine}" style="width:96%"/>
              </f:facet>
          </p:cellEditor>
      </p:column>

    <p:column headerText="1" id="col2">
       <p:cellEditor>
           <f:facet name="output"><h:outputText value="#{car.brand}" /></f:facet>
           <f:facet name="input">
               <h:selectOneMenu value="#{car.brand}" style="width:100%">
                   <f:selectItems value="#{dtEditView.brands}" var="man" itemLabel="#{man}" itemValue="#{man}" />
               </h:selectOneMenu>
           </f:facet>
       </p:cellEditor>
   </p:column>

  <p:column headerText="2" id="col3">
       <p:cellEditor>
           <f:facet name="output"><h:outputText value="#{car.color}" /></f:facet>
           <f:facet name="input">
               <h:selectOneMenu value="#{car.color}" style="width:100%">
                   <f:selectItems value="#{dtEditView.colors}" var="color" itemLabel="#{color}" itemValue="#{color}" />
               </h:selectOneMenu>
           </f:facet>
       </p:cellEditor>
   </p:column>
   </p:dataTable>

   </h:panelGrid>
    </h:form>


    Bean Class:
    @ManagedBean(name="step1Bean")
    public class CalendarView {
    public Boolean showPanel1=false;

    public Boolean getShowPanel1() {
    return showPanel1;
     }

    public void setShowPanel1(Boolean showPanel1) {
    this.showPanel1 = showPanel1;
     }

     public void onClick(ActionEvent actionEvent) {

     this.setShowPanel1(true);
      }
      }


      Ajax Event:

       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+" rowind-"+t1+" col : "+t2);

        FacesContext.getCurrentInstance().addMessage(null, msg);
    }

0 个答案:

没有答案