我正在调用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中更新的数据吗?
在你的bean中使用'RequestContext',并且只有在你的dbaction成功时才从那里更新组件 – Kukeltje