我正在尝试实现一个在 parent.xhtml 中调用的数据表,并且对该数据表进行了一些操作,如更新、删除和取消。 因此,当我尝试在数据表下编辑我的详细信息然后我们尝试取消它时,它用于保留更新的记录,即使我没有保存记录。 所以这些数据表写在不同的 xhtml 文件中,并在 parent.xhtml 文件中调用,因此我无法执行取消操作,写在 parent.xhtml 中
下面的逻辑是数据表写在child.xhtml里面
Child.xhtml->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<h3 class="pagesubheader">
<span style="color: #CC0000; margin-left: 5px;">* </span>Welcome
</h3>
<p:panelGrid columns="1" style="width:100%;margin-left: 5px;"
rendered="#{pbgBean.tblList.tblVal}">
</p:panelGrid>
<br />
<p:panel class="psDetails" style="border:none !important;">
<p:dataTable id="psTbl" var="flipPack"
value="#{pbgBean.tblList.Details}"
paginator="false" lazy="false" editable="true" editMode="cell"
emptyMessage="empty" style="width:100%"
rowKey="#{flipPack.Id}">
<p:ajax event="cellEdit" listener="#{pbgBean.cellEdit}" />
<p:column headerText="*ID"
styleClass="custom-th custom-td custom-label customEditableCol"
style="word-wrap:break-word !important;width:8%;">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{flipPack.Id}" />
</f:facet>
<f:facet name="input">
<p:inputText id="Id" value="#{flipPack.Id}"
style="width: 100% !important;"
maxlength="#{pbgBean.getMaxLength('ORDER_ID')}">
<p:ajax event="change" process="@this" update="messages" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="DESCRIPTION"
styleClass="custom-th custom-td custom-label customEditableCol"
style="word-wrap:break-word !important;width:15%;">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{flipPack.Description}" />
</f:facet>
<f:facet name="input">
<p:inputText id="Desc" value="#{flipPack.Description}"
maxlength="#{pbgBean.getMaxLength('DESC')}"
style="width: 100% !important;" converter="stringtrim">
<p:ajax event="change" process="@this" update="messages" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Weight"
styleClass="custom-th custom-td custom-label customEditableCol"
style="word-wrap:break-word !important;width:15%;">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{flipPack.Weight}" />
</f:facet>
<f:facet name="input">
<p:inputText id="Weight" value="#{flipPack.Weight}"
style="width: 100% !important;" converter="stringtrim"
maxlength="#{pbgBean.getMaxLength('WT')}">
<p:ajax event="keyup"
listener="#{pbgBean.autoPopulateWeight(flipPack)}"
process="@this" update="flipPackForm:WeightD" resetValues="true" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:panel>
</ui:composition>
上面的child.xhtml在parent.xhtml->下调用
<h:panelGroup id="flipPackBlock">
<h:panelGroup id="flipPackContentData" rendered="#{pbgBean.tblList.simFlag}">
<ui:include src="child.xhtml">
<ui:param name="pbgBean" value="#{pbgBean}" />
</ui:include>
</h:panelGroup>
</h:panelGroup>
cancelBtn->
的逻辑<p:commandButton id="cancelBtn" action="#{pbgBean.cancelPbg}" value="CANCEL"
style="width: 170px; height: 37px;" update=":flipPackForm:edit" class="btn-red rounded-corner"
oncomplete="PF('DetailsWidgetvar').hide();" process="@this">
<p:resetInput target="returnWrapper" /></p:commandButton>
cancelBtn 的 Java 逻辑:
public void cancelPbg() {
if (previousDetails != null && CollectionUtils.isNotEmpty(previousDetails.getErrorKeysList())) {
for (ErrorMessage error : previousDetails.getErrorKeysList()) {
GenUtil.updateUIComponents(error.getKey(), true);
}
}
if (flipDetails != null && CollectionUtils.isNotEmpty(flipDetails.getErrorKeysList())) {
for (ErrorMessage error : flipDetails.getErrorKeysList()) {
GenUtil.updateUIComponents(error.getKey(), true);
}
}
previousDetails = new flipPack();
flipDetails = new flipPack();
RequestContext.getCurrentInstance().addCallbackParam("done", true);
}