2015-06-20 30 views
1

我正在调用rowEdit事件,并且仅当事件成功执行数据库更新时才想刷新表。以下是我的代码。primefaces rowEdit仅当事件成功时才更新表的事件

XHTML

<p:dataTable id="xobjTable" var="xobj" value="#{xListView.xListResponseObject}" 
           scrollRows="20" scrollable="true" liveScroll="true" scrollHeight="600" 
           rowKey="#{xobj.X}" 
           selection="#{xListView.selectedObject}" selectionMode="single" 
           style="margin-top: 20px; margin-bottom:20px" editable="true"> 

         <f:facet name="header"> 
          Search Results 
          <p:spacer width="20"/> 
          <h:commandLink id="csv"> 
           <p:graphicImage value="csv.png" width="24"/> 
           <p:dataExporter type="csv" target="xobj" fileName="xListSearch" /> 
           <p:tooltip id="toolTipFade" for="csv" value="Click on CSV to download entire table as a csv file. " /> 
          </h:commandLink> 
         </f:facet> 
         <p:ajax event="rowEdit" listener="#{xListView.onRowEdit}" update=":xListform:xobjTable" /> 
         <p:column headerText="X" style="width:60px;text-align: center"> 
          <h:outputText value="#{xobj.X}" /> 
         </p:column> 
         <p:column headerText="Y" style="width:60px;text-align: center"> 
          <h:outputText value="#{xobj.Y}" /> 
         </p:column> 
         <p:column headerText="Modified Date" style="width:160px;text-align: center"> 
          <h:outputText value="#{xobj.modifiedDate}" /> 
         </p:column> 
         <p:column headerText="Active" style="width:160px;text-align: center"> 
          <p:cellEditor> 
           <f:facet name="output"> 
            <h:outputText value="#{xobj.active}"/> 
           </f:facet> 
           <f:facet name="input"> 
            <h:selectOneMenu value="#{xobj.active}"> 
             <f:selectItems value="#{xListView.activeList}" /> 
            </h:selectOneMenu> 
           </f:facet> 
          </p:cellEditor> 
         </p:column> 
         <p:column headerText="Location" style="width:160px;text-align: center"> 
          <p:cellEditor> 
           <f:facet name="output"> 
            <h:outputText value="#{xobj.location}"/> 
           </f:facet> 
           <f:facet name="input"> 
            <p:inputText id="location" value="#{xobj.location}" /> 
           </f:facet> 
          </p:cellEditor> 
         </p:column> 
         <p:column headerText="State" style="width:160px;text-align: center"> 
          <p:cellEditor> 
           <f:facet name="output"> 
            <h:outputText value="#{xobj.state}"/> 
           </f:facet> 
           <f:facet name="input"> 
            <p:inputText id="state" value="#{xobj.state}" /> 
           </f:facet> 
          </p:cellEditor> 
         </p:column> 
         <p:column headerText="x Country Code" style="width:160px;text-align: center"> 
          <p:cellEditor> 
           <f:facet name="output"> 
            <h:outputText value="#{xobj.xCountryCode}"/> 
           </f:facet> 
           <f:facet name="input"> 
            <p:inputText id="xCountryCode" value="#{xobj.xCountryCode}" /> 
           </f:facet> 
          </p:cellEditor> 
         </p:column> 
         <p:column headerText="xrarier" style="width:160px;text-align: center"> 
          <p:cellEditor> 
           <f:facet name="output"> 
            <h:outputText value="#{xobj.carrier}"/> 
           </f:facet> 
           <f:facet name="input"> 
            <h:selectOneMenu value="#{xobj.carrier}"> 
             <f:selectItems value="#{xListView.xarrierList}" /> 
            </h:selectOneMenu> 
           </f:facet> 
          </p:cellEditor> 
         </p:column> 
         <p:column style="width:32px" headerText="Edit" rendered="#{allTabs.isShow(xListView.title)}"> 
          <p:rowEditor /> 
         </p:column> 
         <p:column style="width:160px;text-align: center" rendered="#{allTabs.isShow(xListView.title)}" headerText="Delete"> 
          <p:commandButton id="deleteDid" actionListener="#{xListView.deletexy(xobj)}" 
              icon="ui-icon ui-icon-trash red" title="Delete" update="@form"> 
           <p:confirm header="Confirmation" message="#{xListView.finalDeleteMessage}" icon="ui-icon-alert" /> 
          </p:commandButton> 
         </p:column> 
        </p:dataTable> 

下面是事件方法

public void onRowEdit(RowEditEvent event) { 
     xListResponseObject editObject = (xListResponseObject) event.getObject(); 
     logger.debug("Coming to edit the row."); 
     String editXYStatus = xListDAO.editxy(editObject); 
     if (editxyStatus.equals(SUCCESS_RESPONSE)) { 
      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "X/Y edit successful!"); 
      FacesContext.getCurrentInstance().addMessage(null, msg); 
     } else { 
      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "INFO", "X/Y edit failed :" + editxyStatus); 
      FacesContext.getCurrentInstance().addMessage(null, msg); 
     } 

    } 

我想发生这样的更新,只有当rowEdit事件更新数据库。 我可以在我的方法中有一个布尔值集并访问p:ajax中更新的数据吗?

+0

在你的bean中使用'RequestContext',并且只有在你的dbaction成功时才从那里更新组件 – Kukeltje

回答

1

添加到结束你SUCCESS_RESPONSE

RequestContext.getCurrentInstance().update("form:npaobjTable"); 

或任何你的表真正的ID是。

+0

我试过了上面的内容,并从p:ajax中删除了更新,并将其添加到rowEdit事件中,但仍然更新了表无效的记录。以下是我的更改。 hopeIsTheonlyWeapon

+0

if(editNpaNxxStatus.equals(SUCCESS_RESPONSE)){FailedMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,“INFO”,“NPA/NXX编辑成功!“); FacesContext.getCurrentInstance()。addMessage(null,msg); RequestContext.getCurrentInstance()。update(“:npaListform:npaobjTable”); } – hopeIsTheonlyWeapon

+0

您没有处理新值

-2

我遇到了同样的问题。 URL下方将解决您的问题。 。

http://forum.primefaces.org/viewtopic.php?f=3&t=38412&p=153402#p153402

实际响应:

public void onRowEdit(RowEditEvent event) { 
     NpaListResponseObject editObject = (NpaListResponseObject) event.getObject(); 
     logger.debug("Coming to edit the row."); 
     String editNpaNxxStatus = npaListDAO.editNpaNxx(editObject); 
     if (editNpaNxxStatus.equals(SUCCESS_RESPONSE)) { 
      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO", "NPA/NXX edit successful!"); 
      FacesContext.getCurrentInstance().addMessage(null, msg); 
     } else { 
      FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "INFO", "NPA/NXX edit failed :" + editNpaNxxStatus); 
      FacesContext.getCurrentInstance().addMessage(null, msg); 
      FacesContext.getCurrentInstance().validationFailed(); 
     } 

    } 

加入FacesContext.getCurrentInstance()validationFailed();最后在失败的情况下。

+0

请在这里添加一个实际的解释和回应,而不只是一个链接到另一个回应 – Pom12

+0

根据您的建议编辑的代码。添加了FacesContext.getCurrentInstance()。validationFailed();在最后一行。 – umeshfadadu

+0

但是,您应该提供一个关于如何解决问题的真实**解释**,例如解释代码的作用,在哪里添加它等等。答案应该是描述性的,而不是一些复制粘贴! – Pom12

相关问题