如何获取已编辑的数据表行的新值?

时间:2014-06-21 07:31:13

标签: jsf

您好我有可编辑的数据表,我想从该行获取新值,因此,以下是我的代码....

此代码适用于DataTable

                                      行编辑

                                  <f:facet name="People">
                                      <p:outputPanel>
                                          <h:outputText value="Search all fields:" />
                                          <p:inputText id="globalFilter"  onkeyup="PF('peoplesTable').filter()" style="width:150px" />
                                      </p:outputPanel>
                                  </f:facet>                                      

                                  <p:ajax event="rowEdit" listener="#{personInformation.onRowEdit}" update="dt" />
                                  <p:ajax event="rowEditCancel" listener="#{personInformation.onRowCancel}"  />   
                                  <p:ajax event="rowSelect" listener="#{personInformation.onRowSelect}" />
                                  <p:ajax event="rowUnselect" listener="#{personInformation.onRowUnselect}" /> 

                                  <p:column style="width:16px">
                                      <p:rowToggler />
                                  </p:column>

                                  <p:column  headerText="व्यक्ती क्र." filterBy="#{per.id}" filterMatchMode="contains" style="width:30px;" >                          
                                    <p:cellEditor  >
                                        <f:facet name="output"><h:outputText value="#{per.id}" /></f:facet>
                                        <f:facet name="input"><h:outputText value="#{per.id}" style="width:100%" /></f:facet>
                                    </p:cellEditor>
                                </p:column>

                                  <p:column headerText="नाव" filterBy="#{per.name}" filterMatchMode="contains" >
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{per.name}" /></f:facet>
                                        <f:facet name="input"><p:inputText value="#{per.name}" style="width:100%" label="Name"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                  <p:column headerText="पत्ता" filterBy="#{per.address}" filterMatchMode="contains" >
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{per.address}" /></f:facet>
                                        <f:facet name="input"><p:inputText value="#{per.address}" style="width:100%" label="Address"/></f:facet>
                                    </p:cellEditor>
                                </p:column>                                    
                                  <p:column headerText="मोबाईल नंबर" filterBy="#{per.mobilenumber}" filterMatchMode="contains"  >
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{per.mobilenumber}" /></f:facet>
                                        <f:facet name="input"><p:inputText value="#{per.mobilenumber}" style="width:100%" label="Mobile Number"/></f:facet>
                                    </p:cellEditor>
                                </p:column>
                                  <p:column headerText="भेटीचे कारण" filterBy="#{per.reason}" filterMatchMode="contains" >
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{per.reason}" /></f:facet>
                                        <f:facet name="input"><p:inputText value="#{per.reason}" style="width:100%" /></f:facet>
                                    </p:cellEditor>
                                </p:column>                                                 
                                  <p:column headerText="भेटीचे वेळ" style="width:200px;" filterBy="#{per.d}" filterMatchMode="contains" >
                                    <p:cellEditor>
                                        <f:facet name="output"><h:outputText value="#{per.d}" /></f:facet>
                                        <f:facet name="input"><h:outputText value="#{per.d}" /></f:facet>
                                    </p:cellEditor>
                                </p:column>                                                  
                                  <p:column style="width:32px">
                                      <p:rowEditor />
                                  </p:column>

                                  <p:rowExpansion  >

                                      <p:panelGrid  columns="2" columnClasses="label,value" style="margin-left: 300px;width:300px">
                                          <h:outputText value="व्यक्ती क्र." />
                                          <h:outputText value="#{per.id}" />

                                          <h:outputText value="नाव" />
                                          <h:outputText value="#{per.name}" />

                                          <h:outputText value="पत्ता" />
                                          <h:outputText value="#{per.address}" />

                                          <h:outputText value="मोबाईल नंबर" />
                                          <h:outputText value="#{per.mobilenumber}" />

                                          <h:outputText value="भेटीचे कारण" />
                                          <h:outputText value="#{per.reason}" />

                                          <h:outputText value="भेटीचे वेळ" />
                                          <h:outputText value="#{per.d}" />
                                      </p:panelGrid>
                                  </p:rowExpansion>
                            </p:dataTable>

并支持Bean,我想在其中显示新编辑的值......

public void onRowSelect(SelectEvent event)
     {

         System.out.println(event.getObject().toString());      
         DataTable objDataTable = (DataTable) event.getSource();
         System.out.println("Get Row Data : "+objDataTable.getRowData("id"));
         PersonBean pb=new PersonBean();
         pb=(PersonBean)objDataTable.getRowData();
         int id=pb.getId();
         String name=pb.getName();
         String address=pb.getAddress();
         String mobilenumber=pb.getMobilenumber();
         String reason=pb.getReason();


}

1 个答案:

答案 0 :(得分:0)

如果你想在数据库更新后从datata获取新值,你应该使用rowEdit事件。

<p:ajax event="rowEdit" listener="#{bean.listener}"/>

<p:column>
   <p:cellEditor>
      <f:facet name="output">
           <h:outputText value="#{per.name}"/>
       </f:facet>
       <f:facet name="input">
             <h:inputText value="#{per.name}" required="true"/>
        </f:facet>
   </p:cellEditor>
  </p:column>

 public void update(RowEditEvent event) {
   // use event.getObject() here
}