I am trying to implement a datatable which is been called within the parent.xhtml and there are some operation with are carried on that data table like update, delete and cancel. So when I am trying to edit my details under datatable and then we are trying to do cancel it used to keep the updated records even if I have not saved the records. So these datatable is written in different xhtml file and it is called in parent.xhtml file due to which I am not able to perform cancel operation with is written inside parent.xhtml
The below logic is for datatable is written inside 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>
The above child.xhtml is called under 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>
Logic for 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>
Java logic for cancelBtn :
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);
}