In a Parent Window i have a List and two commandButton
First commandButton will add a new record in the table.When user will click on this button a popup Window will open, user will give value and submit list will render again and new record will be added .
By second commandButton User can edit the added record by click on this commandbutton for that in parent Window i did below code
Include Popup Like this
< rich: panel id = "includePandel" > < ui: include src = "CfsGroupFeature-Add.xhtml" > < ui: param name = "parentBean"
value = "#{cfsBean}" / > < /ui:include>
</rich: panel >
Here is the Edit button in Parent class which will call popup bean method
action = "#{addFeaturePopUpBean.updateCfsGroupFeature(itemsComp,tableIndex.index)}"
Here is the Whole Command
<a4j: commandButton id ="editAlarm"
image = "/resources/images/table_edit.png"
immediate = "false"
execute = "#this"
actionListener = "#{cfsBean.updateCfsGroupFeature(itemsComp,tableIndex.index)}"
action = "#{addFeaturePopUpBean.updateCfsGroupFeature(itemsComp,tableIndex.index)}"
oncomplete = "#{rich:component('popup')}.show(true)"
render = "includePandel" > < /a4j:commandButton>
and i wrote this code in PopupBean or AddFeaturePopUpBean.java
public void updateCfsGroupFeature(CompositeCharGroupVo compositeCharGroupVo,Integer row) {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
if(sessionMap.get("cfsBean") != null){
CfsBean cfsBean = (CfsBean) sessionMap.get("cfsBean");
selectionRfsGroupFeature = cfsBean.getSelectionRfsGroupFeature();
for (Object object : selectionRfsGroupFeature) {
if(object instanceof Integer){
indexValue = (Integer) object;
if(compositeCharGroupVo != null && compositeCharGroupVo.getFeaturesList() != null && compositeCharGroupVo.getFeaturesList().get(indexValue) != null){
featuesObj = compositeCharGroupVo.getFeaturesList().get(indexValue);
setFeatuesObj(featuesObj);
}
}
}
}
}
Upto here everything working fine and i am able to see the selected row values in popup .
Now in Popup Window if i am clicking on save button then commandButton not invoked ,its just reset(Removed) the pre populated values. Now if again i will submit the form then its working.
Note:- I am using same popup Window for Add new Record and Edit ..Save working fine issue is coming only when i am doing edit.
EDIT :-
JSF Version 2.1.13
Richfaces Version 4.3.5.Final
Javax.el 3.0.0
Servlet 2.4
el-api 2.2
el-impl 2.2
Jboss 7.1.0.Final
Popup Source Code
<?xml version='1.0' encoding='UTF-8' ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<ui:define name="title">Page title</ui:define>
<h:outputScript target="body">
function validateFeatures(formId, valueType, dependentId, fieldName, errorMsgId,isallowedvalue,defvalue,pattern,min,max){
var intRegex = /^\+?[0-9]\d*?$/;
document.getElementById(formId+':'+errorMsgId).innerHTML = "";
var selectedvalueType = document.getElementById(formId+':'+valueType);
var dependentValue = document.getElementById(formId+':'+dependentId);
var capValue = dependentValue.value.split(",");
var defalutValue = document.getElementById(formId+':'+defvalue);
var minvalue = document.getElementById(formId+':'+defvalue);
var maxValue = document.getElementById(formId+':'+defvalue);
var patternRe = document.getElementById(formId+':'+defvalue);
if(selectedvalueType.value == "Integer"){
if(dependentValue.value!==""){
if(isallowedvalue){
for( var i=0; i < capValue.length ; i++){
isInteger = intRegex.test(capValue[i]);
if(!isInteger){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Please enter valid Integer value for "+fieldName;
return false;
}
}
}
else{
isInteger = intRegex.test(dependentValue.value);
if(!isInteger){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Please enter valid Integer value for "+fieldName;
return false;
}
}
}
}
validatAllowedValues(formId,valueType,dependentId,defvalue,isallowedvalue,errorMsgId,pattern,min,max);
}
function validateMaxValues(formId,valType, minval, maxval, errorMsgId){
document.getElementById(formId+':'+errorMsgId).innerHTML = "";
var valueType = document.getElementById(formId+':'+minval);
var dependentValue = document.getElementById(formId+':'+maxval);
var selectedvalueType = document.getElementById(formId+':'+valType);
var intRegexValid = /^\+?[0-9]\d*?$/;
if(selectedvalueType.value == "Integer"){
if(valueType.value!==""){
isValidInteger = intRegexValid.test(valueType.value)
if(!isValidInteger){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Please enter valid Integer value";
return false;
}
}
if(dependentValue.value!==""){
isValidMaxInteger = intRegexValid.test(dependentValue.value)
if(!isValidMaxInteger){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Please enter valid Integer value";
return false;
}
}
if(valueType.value!=="" && dependentValue.value!== "" ){
if( valueType.value < dependentValue.value ){
return true;
}
else{
document.getElementById(formId+':'+errorMsgId).innerHTML = "Maximum value must be greater than Minimum value ";
dependentValue.value="";
return false;
}
}
}
else if(selectedvalueType.value == "String"){
if(valueType.value!=="" && dependentValue.value!== "" ){
if( valueType.value < dependentValue.value){
return true;
}
else{
document.getElementById(formId+':'+errorMsgId).innerHTML = "Maximum Stringth lenght must be greater than Minimum String length";
dependentValue.value="";
return false;
}
}
}
}
function validatAllowedValues(formId,valtyep,allowedvalues,defaultValue,isallowedvalue,errorMsgId,patternval,min,max){
document.getElementById(formId+':'+errorMsgId).innerHTML = "";
var allowed2 = document.getElementById(formId+':'+valtyep);
var allowedValues1 = document.getElementById(formId+':'+allowedvalues);
var defavlue1 = document.getElementById(formId+':'+defaultValue);
var tovalidate;
var ismatch= false;
var patternRegex = document.getElementById(formId+':'+patternval);
var minval = document.getElementById(formId+':'+min);
var maxval = document.getElementById(formId+':'+max);
re = new RegExp(patternRegex.value);
if(isallowedvalue){
tovalidate=allowedValues1;
}
else{
tovalidate=defavlue1;
defavlue1 =allowedValues1;
}
var sepValue= tovalidate.value.split(",");
if(tovalidate.value!="" && defavlue1.value!=""){
if(allowed2.value == "Integer" || allowed2.value == "String"){
for(var j=0; j < sepValue.length ; j++){
if(sepValue[j] === defavlue1.value){
ismatch=true;
break;
}
}
if(!ismatch){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Default values must be equal to one of the allowed values ";
return false;
}
}
}
else{
if(patternRegex.value!=="" && defavlue1.value!==""){
isPattenrMatch = re.test(defavlue1.value);
if(!isPattenrMatch){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Default values must be match with Pattern";
return false;
}
if(minval.value!=="" && maxval.value!==""){
if(allowed2.value == "Integer"){
if(defavlue1.value < minval.value || defavlue1.value > maxval.value){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Default values must be in between min and Max value";
return false;
}
}
if(allowed2.value == "String"){
if(defavlue1.value.length < minval.value || defavlue1.value.length > maxval.value){
document.getElementById(formId+':'+errorMsgId).innerHTML = "Default value Length must be in between min and Max value";
return false;
}
}
}
}
}
}
</h:outputScript>
<rich:popupPanel id="popup" modal="true" resizeable="false"
height="600" width="380" autosized="true" domElementAttachment="form" >
<f:facet name="header">
<h:outputText value="Add Group Feature" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('popup')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<h:form id="popupform">
<h:messages globalOnly="true" />
<rich:focus />
<h:panelGroup id="notification">
<rich:notify stayTime="2000"
rendered="#{flash.errorMessage.length() > 0 }"
styleClass=".rf-ntf-cnt" showShadow="false" sticky="false">
<f:facet name="detail">
<rich:panel id="flashErrorMessage"
style="background-color:#ffebe8; padding:15px 0 15px 10px; border-radius:0 0 0 0;display:inherit;">
<h:graphicImage value="../resources/images/stop.png" />
Failed: #{flash.errorMessage}
</rich:panel>
</f:facet>
</rich:notify>
<rich:notify stayTime="2000"
rendered="#{flash.successMessage.length() > 0 }"
styleClass="rf-ntf-cnt" showShadow="false" sticky="false">
<f:facet name="detail">
<rich:panel id="successfullFlashIdMessage"
style=" padding:15px 0 15px 10px; border-radius:0 0 0 0">
<h:graphicImage value="../resources/images/success.png" />
Success: #{flash.successMessage}
</rich:panel>
</f:facet>
</rich:notify>
<rich:notify stayTime="2000"
rendered="#{flash.warningMessage.length() > 0 }"
styleClass=".rf-ntf-cnt" showShadow="false" sticky="false">
<f:facet name="detail">
<rich:panel id="notifyWarningMessage"
style="background-color:#ffebe8; padding:15px 0 15px 10px; border-radius:0 0 0 0">
<h:graphicImage
value="../resources/images/Button-Warning-icon.png" height="20"
width="20" />
Warning: #{flash.warningMessage}
</rich:panel>
</f:facet>
</rich:notify>
</h:panelGroup>
<a4j:outputPanel id="search-filter">
<table cellspacing="20px">
<tr>
<td><h:outputText value="Name" /> <h:outputText value=" *"
style="color:red" /></td>
<td><h:inputText style="width:142px" id="featureName"
value="#{addFeaturePopUpBean.featuesObj.name}"
validatorMessage="#{bsmPortalMessage['message.catalog.validation.compositeChar.name']}">
<f:validateRequired />
<f:validateRegex pattern="^[a-zA-Z0-9][a-zA-Z0-9_-]*$"></f:validateRegex>
<rich:validator event="blur" />
</h:inputText> <br /> <rich:message for="featureName" /></td>
</tr>
<tr>
<td><h:outputText value="Desc" /></td>
<td><h:inputText style="width:142px" id="description"
value="#{addFeaturePopUpBean.featuesObj.desc}">
</h:inputText></td>
</tr>
<tr>
<td><h:outputText value="GloballySet" /></td>
<td><h:selectOneMenu
value="#{addFeaturePopUpBean.featuesObj.globallySet}"
disabled="false" style="width:155px">
<f:selectItem itemValue="Yes" itemLabel="Yes" />
<f:selectItem itemValue="No" itemLabel="No" />
</h:selectOneMenu></td>
</tr>
<tr>
<td><h:outputText value="Mandatory" /></td>
<td><h:selectOneMenu
value="#{addFeaturePopUpBean.featuesObj.mandatory}"
disabled="false" style="width:155px">
<f:selectItem itemValue="False" itemLabel="False" />
<f:selectItem itemValue="True" itemLabel="True" />
</h:selectOneMenu></td>
</tr>
<tr>
<td><h:outputText value="Value Type" /> <h:outputText
value="*" style="color:red;" /></td>
<td><h:selectOneMenu id="valueType"
value="#{addFeaturePopUpBean.featuesObj.valueType}"
style="width:155px" immediate="true"
valueChangeListener="#{addFeaturePopUpBean.valueTypeChanged}"
validatorMessage="#{bsmPortalMessage['message.validation.catalog.valueType']}">
<f:selectItem noSelectionOption="false" itemDisabled="true"
itemLabel="#{bsmPortalLabel['label.rfs.type.selectone']}" />
<f:selectItem itemValue="Integer" itemLabel="Integer" />
<f:selectItem itemValue="String" itemLabel="String" />
<f:selectItem itemValue="Boolean" itemLabel="Boolean" />
<f:selectItem itemValue="IP Address" itemLabel="IP Address" />
<f:validateRequired />
<a4j:ajax event="valueChange"
render="dis,enab,mindis,minena,maxdis,maxenab,acceptIP,acceptInt,acceptBool,defaultIP,defaultInt,defaultBool"
execute="#this" />
</h:selectOneMenu> <rich:message for="valueType" /></td>
</tr>
<tr>
<td><h:outputText value="Pattern" /></td>
<td><h:panelGroup id="dis">
<a4j:outputPanel id="patternDis"
rendered="#{addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="pattern"
value="#{addFeaturePopUpBean.featuesObj.pattern}"
disabled="true">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="enab">
<a4j:outputPanel id="patternenable"
rendered="#{!addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="pattern12"
value="#{addFeaturePopUpBean.featuesObj.pattern}"
validatorMessage="#{bsmPortalMessage['message.catalog.validation.pattern']}"
converterMessage="#{bsmPortalMessage['message.catalog.validation.pattern']}"
immediate="true">
<f:validator validatorId="patternValidator" />
<f:ajax event="blur" execute="pattern12" render="message1" />
</h:inputText>
<h:message id="message1" for="pattern12" style="color:red" />
</a4j:outputPanel>
</h:panelGroup></td>
</tr>
<tr>
<td><h:outputText value="Min" /></td>
<td><h:panelGroup id="mindis">
<a4j:outputPanel id="mindisable"
rendered="#{addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="min1"
value="#{addFeaturePopUpBean.featuesObj.min}" disabled="true">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="minena">
<a4j:outputPanel id="ninenable"
rendered="#{!addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="min"
onchange="validateMaxValues('contentform:popupform', 'valueType','min', 'max','minValue');"
onblur="validateMaxValues('contentform:popupform', 'min', 'max','minValue');"
value="#{addFeaturePopUpBean.featuesObj.min}">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup></td>
<td><h:outputLabel id="minValue" value="" style="color:red" /></td>
</tr>
<tr>
<td><h:outputText value="Max" /></td>
<td><h:panelGroup id="maxdis">
<a4j:outputPanel id="disbaleMax"
rendered="#{addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="max1" disabled="true"
value="#{addFeaturePopUpBean.featuesObj.max}">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="maxenab">
<a4j:outputPanel id="enableMax"
rendered="#{!addFeaturePopUpBean.disabled}">
<h:inputText style="width:142px" id="max"
onchange="validateMaxValues('contentform:popupform', 'valueType','min', 'max','miValue');"
onblur="validateMaxValues('contentform:popupform', 'min', 'max','miValue');"
value="#{addFeaturePopUpBean.featuesObj.max}">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup></td>
<td><h:outputLabel id="miValue" value="" style="color:red" /></td>
</tr>
<tr>
<td><h:outputText value="Allowed values" /></td>
<td><h:panelGroup id="acceptIP">
<a4j:outputPanel id="IpAllowe"
rendered="#{addFeaturePopUpBean.IPselecetd}">
<h:inputText style="width:142px" id="IPadree"
validatorMessage="#{bsmPortalErrorMessage['errorMessage.common.validator.invalidip']}"
value="#{addFeaturePopUpBean.featuesObj.allowedValues}">
<f:validateRegex
pattern="^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$|\s*">
</f:validateRegex>
<rich:validator />
</h:inputText>
<rich:message for="IPadree" />
<br />
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="acceptInt">
<a4j:outputPanel id="allowedInt"
rendered="#{addFeaturePopUpBean.otherselecetd}">
<h:inputText style="width:142px" id="allowedvalues"
onblur="validateFeatures('contentform:popupform', 'valueType', 'allowedvalues', 'Allowed values','allowedValErrorMsg',true,'default','pattern12','min','max');"
value="#{addFeaturePopUpBean.featuesObj.allowedValues}">
</h:inputText>
</a4j:outputPanel>
</h:panelGroup> <br /> <h:outputLabel id="allowedValErrorMsg" value=""
style="color:red" /> <h:panelGroup id="acceptBool">
<a4j:outputPanel id="allowedBool"
rendered="#{addFeaturePopUpBean.booleanselecetd}">
<h:selectOneMenu id="booleSelc"
value="#{addFeaturePopUpBean.featuesObj.allowedValues}"
style="width:155px">
<f:selectItem noSelectionOption="false" itemDisabled="true"
itemLabel="#{bsmPortalLabel['label.rfs.type.selectone']}" />
<f:selectItem itemValue="True,False" itemLabel="True,False" />
</h:selectOneMenu>
</a4j:outputPanel>
</h:panelGroup></td>
</tr>
<tr>
<td><h:outputText value="Default" /></td>
<td><h:panelGroup id="defaultIP">
<a4j:outputPanel id="Ipdefault"
rendered="#{addFeaturePopUpBean.IPselecetd}">
<h:inputText style="width:142px" id="IPadree1"
validatorMessage="#{bsmPortalErrorMessage['errorMessage.common.validator.invalidip']}"
value="#{addFeaturePopUpBean.featuesObj.defaultval}">
<f:validateRegex
pattern="^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$|\s*">
</f:validateRegex>
<rich:validator />
</h:inputText>
<rich:message for="IPadree1" />
<br />
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="defaultBool">
<a4j:outputPanel id="booldefault"
rendered="#{addFeaturePopUpBean.booleanselecetd}">
<h:selectOneMenu id="booleSelc1"
value="#{addFeaturePopUpBean.featuesObj.defaultval}"
style="width:155px">
<f:selectItem noSelectionOption="false" itemDisabled="true"
itemLabel="#{bsmPortalLabel['label.rfs.type.selectone']}" />
<f:selectItem itemValue="False" itemLabel="False" />
<f:selectItem itemValue="True" itemLabel="True" />
</h:selectOneMenu>
</a4j:outputPanel>
</h:panelGroup> <h:panelGroup id="defaultInt">
<a4j:outputPanel id="Ipdefault1"
rendered="#{addFeaturePopUpBean.otherselecetd}">
<h:inputText style="width:142px" id="default"
onblur="validateFeatures('contentform:popupform', 'valueType', 'default', 'Default','defaultErrorMsg',false,'allowedvalues','pattern12','min','max');"
value="#{addFeaturePopUpBean.featuesObj.defaultval}">
</h:inputText>
<br />
<h:outputLabel id="defaultErrorMsg" value="" style="color:red" />
</a4j:outputPanel>
</h:panelGroup></td>
</tr>
</table>
</a4j:outputPanel>
<div class="divTableFooter" align="right" id="footerDivfilter">
<a4j:commandButton
action="#{addFeaturePopUpBean.addFeature(parentBean)}"
value="#{bsmPortalLabel['button.common.submit']}"
image="/resources/images/submit-arrow.png"
render="cfsCreate,createRfs,createReso,notification,search-filter" >
<rich:tooltip id="toolemsSubmit" layout="block" render=":popup :popupform">
<span style="white-space: nowrap">
#{bsmPortalLabel['tooltip.common.submit']}</span>
</rich:tooltip>
</a4j:commandButton>
<h:commandButton type="image" id="backbuttonEms"
value="#{bsmPortalLabel['button.common.back']}"
onclick="#{rich:component('popup')}.hide(); return false;"
image="/resources/images/back.png">
<rich:tooltip id="toolemsback" layout="block">
<span style="white-space: nowrap">
#{bsmPortalLabel['tooltip.common.back']}</span>
</rich:tooltip>
</h:commandButton>
</div>
</h:form>
</rich:popupPanel>
</ui:composition>
Unfortunately I cannot comment but I would suggest to change:
domElementAttachment="form"
to
domElementAttachment="parent"
because it looks like you attached your popup with form to some other outside form. Try to put rich:popupPanel inside form, it works for me.
Also add execute="#this, search-filter" to a4j:commandButton.
UPDATE AFTER INVESTIGATION
<a4j:outputPanel> could breaks request because of ajaxRendered="true" default value.
I have this problem and I search here and some pages on Google and none of the answers worked for me.
I have the following dialog:
<!-- Dialog Fechar Pedido -->
<p:dialog header="Fechar Pedido" widgetVar="clsPedido" id="clsPedido" minWidth="550">
<h:form prependId="true" id="frmClsPedido">
<p:panel id="pnlDialogClsPedido" header="Informe a forma de pagamento">
<h:panelGrid id="grdClsPedido" columns="2" cellpadding="5">
<p:outputLabel value="Valor Total:." />
<p:outputLabel value="R$ #{pedidoMB.totalPedido}" size="5" style="color: red;">
<f:convertNumber currencySymbol="R$" integerOnly="true" pattern="#0.00" locale="pt_BR" minFractionDigits="1" minIntegerDigits="1" />
</p:outputLabel>
<p:outputLabel value="Valor Recebido:." />
<pe:inputNumber id="vlrRecebido" value="#{pedidoMB.vlrRecebido}" minValue="0" required="true" onblur="returnValue(this.value)" requiredMessage="Informe o valor recebido!" decimalPlaces="2" decimalSeparator="," thousandSeparator="." />
<p:outputLabel value="Pagamento em:." />
<p:selectOneRadio id="frmPagamento" value="#{pedidoMB.frmPagamento}" onchange="daTroco(this.value);" required="true" requiredMessage="Informe a forma de pagamento!">
<f:selectItem itemLabel="Dinheiro" itemValue="DIN" />
<f:selectItem itemLabel="Débito" itemValue="DEB" />
<f:selectItem itemLabel="Crédito" itemValue="CRED" />
<f:selectItem itemLabel="Vale Refeição" itemValue="REF" />
</p:selectOneRadio>
<p:outputLabel value="Valor Troco:." />
<p:inputText value="#{pedidoMB.vlrTroco}" size="5" style="color: blue;" id="vlrTroco" widgetVar="vlrTroco" readonly="true">
<f:convertNumber currencySymbol="R$" integerOnly="true" pattern="#0.00" locale="pt_BR" minFractionDigits="1" minIntegerDigits="1" />
</p:inputText>
</h:panelGrid>
<h:messages></h:messages>
<div align="right">
<p:commandButton icon="ui-icon-disk" actionListener="#{pedidoMB.doFecharPedido}" />
</div>
</p:panel>
</h:form>
</p:dialog>
And I have the following method at my mbean:
public void doFecharPedido(ActionEvent event) {
if (getId() != null) {
Pedido p = getService().findById(getId());
getService().fecharPedido(getVlrRecebido(), getVlrTroco(), p);
}
}
I already tried removing the mbean ActionEvent but nothing seems to work.
Why not simply write
<p:commandButton icon="ui-icon-disk" action="#{pedidoMB.doFecharPedido}" />
and
public void doFecharPedido() {
if(getId() != null) {
Pedido p = getService().findById(getId());
getService().fecharPedido(getVlrRecebido(), getVlrTroco(), p);
}
}
?
The problem was a validation error. For some reason the inputNumber from PF extension does not accept a paste value or some other form of automatic fill of the field.
Here, XHTML code, Which have 2primeface datatable.
I want to pass dialog box inputText value to addRow() of Managed Bean with #{invoice.id} value.
But value of all inputText is become NULL.
After new row data will update in invoiceTable and display new entery.
<p:panelGrid columns="3">
<p:outputLabel value="Enter Invoice Number :" />
<p:inputText id="inputInvoiceNumber"
value="#{invoiceBean.invoiceNumber}" />
<p:commandButton value="Search" type="submit">
<f:ajax execute="inputInvoiceNumber" render="outputInvoiceNumber" />
</p:commandButton>
</p:panelGrid>
<br />
<p:dataTable id="outputInvoiceNumber"
value="#{invoiceBean.invoices}" var="invoice">
<p:column headerText="Invoice Id ">
<p:outputLabel value="#{invoice.id}" />
</p:column>
<p:column headerText="Email">
<p:outputLabel value="#{invoice.email}" />
</p:column>
<p:column headerText="Invoice Number ">
<p:outputLabel value="#{invoice.invoiceNumber}" />
</p:column>
<p:column headerText="Date">
<p:outputLabel value="#{invoice.date}" />
</p:column>
<p:column headerText="Delivery Note ">
<p:outputLabel value="#{invoice.deliveryNote}" />
</p:column>
<p:column headerText="Supplier Reference">
<p:outputLabel value="#{invoice.supplierReference}" />
</p:column>
<p:column headerText="Other Reference">
<p:outputLabel value="#{invoice.otherReference}" />
</p:column>
<p:column headerText="Buyer Name">
<p:outputLabel value="#{invoice.buyerName}" />
</p:column>
<p:column headerText="Buyer Address">
<p:outputLabel value="#{invoice.buyerAddress}" />
</p:column>
<p:column headerText="Dispatch Document Date">
<p:outputLabel value="#{invoice.dispatchDocumentDate}" />
</p:column>
<p:column headerText="Dispatch Through">
<p:outputLabel value="#{invoice.dispatchThrough}" />
</p:column>
<p:column headerText="Destination">
<p:outputLabel value="#{invoice.destination}" />
</p:column>
<p:column headerText="Terms Of Delivery">
<p:outputLabel value="#{invoice.termsOfdelivery}" />
</p:column>
<p:column headerText="Net Total">
<p:outputLabel value="#{invoice.netTotal}" />
</p:column>
</p:dataTable>
<br />
<p:dataTable id="invoiceTable" var="invoiceProductsServicesDetail"
value="#{invoiceBean.invoiceProductsServicesDetails}" border="1"
editable="true">
<p:column headerText="Sr. No.">
<p:outputLabel
value="#{invoiceProductsServicesDetail.serialNumber}" />
</p:column>
<p:column headerText="Description of Goods">
<p:outputLabel
value="#{invoiceProductsServicesDetail.descriptionOfGoodsOrService}" />
</p:column>
<p:column headerText="HSN Code">
<p:outputLabel value="#{invoiceProductsServicesDetail.hsnCode}" />
</p:column>
<p:column headerText="Quantity">
<p:outputLabel value="#{invoiceProductsServicesDetail.quantity}" />
</p:column>
<p:column headerText="Rate">
<p:outputLabel value="#{invoiceProductsServicesDetail.rate}" />
</p:column>
<p:column headerText="Percentage Discount">
<p:outputLabel
value="#{invoiceProductsServicesDetail.percentDiscount}" />
</p:column>
<p:column headerText="Amount">
<p:outputLabel
value="#{(invoiceProductsServicesDetail.rate) * (invoiceProductsServicesDetail.percentDiscount) }" />
</p:column>
<p:summaryRow>
<p:column colspan="5" style="text-align:right">
<p:outputLabel value="Total" />
</p:column>
<p:column>
<p:outputLabel value="#{invoiceBean.netTotal}" />
</p:column>
</p:summaryRow>
<f:facet name="footer">
<p:commandButton value="Add Invoice" type="button"
onclick="PF('addInvoice').show();" />
</f:facet>
</p:dataTable>
<p:dialog id="invoiceDialog" header="Add Invoice"
widgetVar="addInvoice" minHeight="40" showEffect="explode"
hideEffect="fold">
<table border="1" id="dialogTable">
<tr>
<td><p:outputLabel value="Description Of Goods Or Services" /></td>
<td><p:outputLabel value="HSN Code" /></td>
<td><p:outputLabel value="Quantity" /></td>
<td><p:outputLabel value="Rate" /></td>
<td><p:outputLabel value="Percentage Discount" /></td>
</tr>
<tr>
<td><p:inputTextarea id="description"
value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45"
required="true" label="Description"
requiredMessage="Description Require Entry" /></td>
<td><p:inputText value="#{invoiceBean.hsnCode}" size="6" /></td>
<td><p:inputText id="quaintity"
value="#{invoiceBean.quantity}" size="3" styleClass="Alingment"
required="true" label="Quantity"
requiredMessage="Quantity Require Entry" autocomplete="off" /></td>
<td><p:inputText id="rate" value="#{invoiceBean.rate}"
styleClass="Alingment" required="true" label="Rate"
requiredMessage="Rate Require Entry" autocomplete="off" /></td>
<td><p:inputText value="#{invoiceBean.percentDiscount}"
size="2" styleClass="Alingment" autocomplete="off" /></td>
</tr>
</table>
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="#this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
<p:growl id="growl" showDetail="true" sticky="true" />
</p:dialog>
<br />
<p:commandButton value="Create Pdf"
action="#{createPdf.createPdfFile}" ajax="false">
<f:setPropertyActionListener value="#{invoiceBean.invoiceNumber}"
target="#{createPdf.invoiceNumber}" />
</p:commandButton>
</h:panelGroup>
Here, Managed Bean addRow() method which use to add new row in invoiceTable with new value of dialog box input : invoiceBean
public void addRow() {
invoiceProductsServicesDetail = new InvoiceProductsServicesDetail();
invoiceDao = new InvoiceDao();
FacesContext facesContext = FacesContext.getCurrentInstance();
DataTable dataTable = (DataTable) facesContext.getViewRoot()
.findComponent("form:invoiceTable");
UIComponent uiTable = ComponentUtils.findParentForm(facesContext,
dataTable);
final AjaxBehavior behavior = new AjaxBehavior();
try {
if (descriptionOfGoodsOrService != ""
&& descriptionOfGoodsOrService != null && rate != 0
&& quantity != 0) {
invoiceProductsServicesDetail.setSerialNumber(dataTable
.getRowCount() + 1);
invoiceProductsServicesDetail
.setDescriptionOfGoodsOrService(descriptionOfGoodsOrService);
invoiceProductsServicesDetail.setHsnCode(hsnCode);
invoiceProductsServicesDetail
.setPercentDiscount(percentDiscount);
invoiceProductsServicesDetail.setQuantity(quantity);
invoiceProductsServicesDetail.setRate(rate);
invoiceProductsServicesDetail.setInvoiceId(id);
invoiceProductsServicesDetails
.add(invoiceProductsServicesDetail);
amount = (rate * quantity);
this.grossTotal = amount = (amount - (amount * (percentDiscount / 100)));
this.netTotal = ((amount) + (amount * (Constants.VAT / 100)) + (amount * (Constants.SERVICE_TAX / 100)));
System.out.println(grossTotal);
System.out.println(netTotal);
invoiceDao
.insertInvoiceProductsServicesDetail(invoiceProductsServicesDetail);
RowEditEvent rowEditEvent = new RowEditEvent(uiTable, behavior,
invoiceProductsServicesDetail);
rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
dataTable.broadcast(rowEditEvent);
}
} catch (AbortProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Your dialog submit button
<p:commandButton type="submit" value="Save New Invoice"
action="#{invoiceBean.addRow}" update=":form:invoiceTable growl"
process="#this invoiceTable" onsuccess="PF('addInvoice').hide();"
onerror="PF('addInvoice').show();">
<f:ajax render=":form:invoiceTable" />
</p:commandButton>
Only processes itself and the invoiceTable and not the invoiceDialog with all the values you enter in the dialog. Try changing it to
process="#form invoiceTable"
to process the whole dialog. Additionally, it is advisable to contain a dialog in an own form to be able to process the form without having to process all surrounding input elements not related to the dialog.
There are several primefaces inputtext controls and commandbuttons in a single form. Pressing the return ket on one inputtext need to activate the click of related commandbutton. How can I achieve that functionality? I tried to use onkeydown even, but could not find out the method.
You can try(you need to find to detect enter key in javascript by yourself)
xhtml:
<p:input onkeydown="test()" />
<p:commandButton styleClass="foo" />
javascript:
function test(){
$('.foo').click();
}
You can see also:
How-to-programmatically-trigger-onclick-event
and
How-to-refer-to-a-jsf-component-id-in-jquery
As guided by RongNK, I changed my code as below and it serves my purpose perfectly.
Added CDATA to include JavaScript.
Used \\ to escape : in id of JSF compoents
<h:form id="frmEn">
<script type="text/javascript" language="JavaScript">
//<![CDATA[
function forDx(e) {
if (e.keyCode === 13) {
$('#frmEn\\:btnDx').click();
return false;
} else {
return true;
}
}
function forIx(e) {
if (e.keyCode === 13) {
$('#frmEn\\:btnIx').click();
return false;
} else {
return true;
}
}
function forMx(e) {
if (e.keyCode === 13) {
$('#frmEn\\:btnMx').click();
return false;
} else {
return true;
}
}
function forRx(e) {
if (e.keyCode === 13) {
$('#frmEn\\:btnRx').click();
return false;
} else {
return true;
}
}
// ]]>
</script>
<p:panel header="Encounter" >
<h:panelGrid columns="2" >
<p:panel header="Encounter Details" >
<h:panelGrid columns="4" >
<h:outputLabel value="Tests" ></h:outputLabel>
<p:autoComplete id="txtIx" value="#{encounterController.test }" completeMethod="#{encounterController.completeIx}" styleClass="defaultTxt" onkeydown="return forIx(event)" >
</p:autoComplete>
<h:commandButton id="btnIx" value="Add" action="#{encounterController.addTest()}">
<f:ajax execute="btnIx txtIx" render="tblIx" />
</h:commandButton>
<p:dataTable value="#{encounterController.ecIxs }" var="ix" id="tblIx" >
<p:column >
<f:facet name="header" >
<h:outputLabel value="Tests"/>
</f:facet>
<h:outputLabel value="#{ix.concept.name}"></h:outputLabel>
</p:column>
</p:dataTable>
<h:outputLabel value="Diagnosis" ></h:outputLabel>
<p:autoComplete id="txtDx" value="#{encounterController.diagnosis }" completeMethod="#{encounterController.completeDx}" styleClass="defaultTxt" onkeydown="return forDx(event)" />
<h:commandButton id="btnDx" value="Add" action="#{encounterController.addDiagnosis()}" >
<f:ajax execute="btnDx txtDx" render="tblDx txtDx" />
</h:commandButton>
<p:dataTable value="#{encounterController.ecDxs }" var="dx" id="tblDx" >
<p:column >
<f:facet name="header" >
<h:outputLabel value="Diagnoses"/>
</f:facet>
<h:outputLabel value="#{dx.concept.name}"></h:outputLabel>
</p:column>
</p:dataTable>
<h:outputLabel value="Treatment" ></h:outputLabel>
<p:autoComplete id="txtRx" value="#{encounterController.rx}" completeMethod="#{encounterController.completeRx}" styleClass="defaultTxt" onkeydown="return forRx(event)">
</p:autoComplete>
<h:commandButton id="btnRx" value="Add" action="#{encounterController.addRx()}">
<f:ajax execute="btnRx txtRx" render="tblRx" />
</h:commandButton>
<p:dataTable value="#{encounterController.ecRxs }" var="rx" id="tblRx" >
<p:column >
<f:facet name="header" >
<h:outputLabel value="Treatment"/>
</f:facet>
<h:outputLabel value="#{rx.concept.name}"></h:outputLabel>
</p:column>
</p:dataTable>
<h:outputLabel value="Plan" ></h:outputLabel>
<p:autoComplete id="txtMx" value="#{encounterController.plan }" completeMethod="#{encounterController.completeMx}" styleClass="defaultTxt" onkeydown="return forMx(event)">
</p:autoComplete>
<h:commandButton id="btnMx" value="Add" action="#{encounterController.addPlanOfAction() }">
<f:ajax execute="btnMx txtMx" render="tblMx" />
</h:commandButton>
<p:dataTable value="#{encounterController.ecMxs}" var="mx" id="tblMx" >
<p:column >
<f:facet name="header" >
<h:outputLabel value="Plan"/>
</f:facet>
<h:outputLabel value="#{mx.concept.name}"></h:outputLabel>
</p:column>
</p:dataTable>
<h:outputLabel value="Details" ></h:outputLabel>
<h:inputTextarea value="#{encounterController.current.comments}" styleClass="defaultTxtArea"></h:inputTextarea>
<h:outputLabel value="" ></h:outputLabel>
<h:outputLabel value="" ></h:outputLabel>
<h:outputLabel value="Charges" ></h:outputLabel>
<h:inputTextarea value="#{encounterController.current.charge}" styleClass="defaultTxt"></h:inputTextarea>
<h:outputLabel value="" ></h:outputLabel>
<h:outputLabel value="" ></h:outputLabel>
<h:outputLabel value=""></h:outputLabel>
<h:commandButton value="Save" action="#{encounterController.saveSelected()}"></h:commandButton>
<h:outputLabel value="" ></h:outputLabel>
<h:outputLabel value="" ></h:outputLabel>
</h:panelGrid>
</p:panel>
<p:panel header="Patient Details" >
<h:panelGrid columns="2" >
<h:outputLabel value="Name"></h:outputLabel>
<h:outputLabel value="#{encounterController.current.patient.person.name}"></h:outputLabel>
<h:outputLabel value="Age"></h:outputLabel>
<h:outputLabel value="#{encounterController.current.patient.person.age}"></h:outputLabel>
<h:outputLabel value="Date of Birth"></h:outputLabel>
<h:outputLabel value="#{encounterController.current.patient.person.dob}">
<f:convertDateTime pattern="dd MMMM yyyy" />
</h:outputLabel>
<h:outputLabel value="Sex"></h:outputLabel>
<h:outputLabel value="#{encounterController.current.patient.person.sex.name}"></h:outputLabel>
<h:outputLabel value="Address"></h:outputLabel>
<h:outputLabel value="#{encounterController.current.patient.person.address}"></h:outputLabel>
</h:panelGrid>
</p:panel>
</h:panelGrid>
</p:panel>
</h:form>
Command button onclick event is not working its not invoking Banking bean Method. There are some other commandButtons like
action="#{editBean.editQuestionAction}"
action="#{editBean.addNewQuestionAction}"
were working fine but its not in the case of `action="#{editBean.updateQuestionAction}"
<p:tab title="Questions">
<h:outputText value="Select a project to add questions: " />
<h:selectOneMenu id="projects_dpd" value="#{editBean.currentProject.projectId}" onchange="">
<f:selectItems value="#{projectBean.projects}" />
</h:selectOneMenu><br/>
<h:form id="listForm">
<p:panel id="listPanel" header="List of Questions" toggleable="false" closable="false">
<p:dataList paginatorAlwaysVisible="false" paginatorPosition="bottom" effect="slide"
value="#{editBean.editBeanList}" var="q"
paginator="true" rows="5" effectSpeed="fast"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<p:commandButton action="#{editBean.**editQuestionAction**}" update="editPanel" title="Edit Question" image="edit">
<f:setPropertyActionListener value="#{q}" target="#{editBean.editQuestion}" />
</p:commandButton>
<p:spacer width="30" height="30" />
<h:outputText value="#{q.question.questionId} -> #{q.question.questionText} ->"/> <b><h:outputText value="#{q.question.questionType}" /></b>
</p:column>
</p:dataList>
<p:commandButton value="New Question !!" action="#{editBean.**addNewQuestionAction**}" update="editPanel" />
<p:commandButton ajax="false" value="Home Page !!" action="#{indexBean.**gotoHomePage}**" />
</p:panel>
</h:form>
<p:layoutUnit position="center" scrollable="true">
<p:panel id="editPanel" header="Edit Section" toggleable="false" closable="false" >
<h:form id="form">
<table cellspacing="20">
<tr>
<td><h:outputLabel value="Question Text:" /></td>
<td><p:inputTextarea id="questionText" required="true" value="#{editBean.editQuestion.question.questionText}" autoResize="true" effectDuration="400" maxHeight="100" /></td> <td><p:message for="questionText" /></td>
</tr>
<tr>
<td>Review:</td>
<td><p:inputTextarea id="reviewText" required="true" value="#{editBean.editQuestion.question.reviewText}" autoResize="true" effectDuration="400" maxHeight="100" /></td>
<td><p:message for="reviewText" /></td>
</tr>
<tr>
<td>Option Type:</td>
<td>
<h:selectOneRadio label="Option Type" value="#{editBean.editQuestion.question.optionType}">
<f:selectItem itemLabel="Currency" itemValue="currency" />
<f:selectItem itemLabel="Hours" itemValue="hours" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td>Question Type:</td>
<td>
<h:selectOneRadio label="Question Type" value="#{editBean.editQuestion.question.questionType}">
<f:selectItem itemLabel="Mandatory" itemValue="mandatory" />
<f:selectItem itemLabel="Linked" itemValue="linked" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td align="right">
<h:selectBooleanCheckbox label="Hide Weight until Review !!" value="#{editBean.editQuestion.question.hideWeight}" />
</td>
<td>Hide Weight Until Review</td>
</tr>
<tr>
<td>Options:</td>
<td>
<p:panel header="Add Option">
<h:panelGrid columns="2" id="grid">
<h:outputLabel value="Text : " for="txt_title"></h:outputLabel>
<p:inputText id="txt_title"
value="#{editBean.placeHolderForOption.optionText}" />
<h:outputLabel value="Weight : " for="txt_author"></h:outputLabel>
<p:inputText id="txt_author"
value="#{editBean.placeHolderForOption.weight}" />
<p:commandButton value="Reset" type="reset"/>
<p:commandButton value="Add" update="options #parent"
action="#{editBean.initOption}" >
<p:collector value="#{editBean.placeHolderForOption}"
addTo="#{editBean.editQuestion.options}" />
</p:commandButton>
</h:panelGrid>
</p:panel>
<p:outputPanel id="options">
<p:dataTable value="#{editBean.editQuestion.options}" var="opt">
<p:column headerText="Text" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.optionText}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.optionText}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Weight" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.weight}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.weight}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Linked Question" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.linkedQuestionId}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{opt.linkedQuestionId}">
<f:selectItems value="#{editBean.linkedQuestionIds}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Display Order" style="width:150px">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{opt.displayOrder}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{opt.displayOrder}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Operation" />
</f:facet>
<p:commandLink value="Remove" update="form:options" process="#this">
<p:collector value="#{opt}"
removeFrom="#{editBean.editQuestion.options}" />
</p:commandLink>
<p:spacer width="10" />
<p:rowEditor />
</p:column>
</p:dataTable>
</p:outputPanel>
</td>
</tr>
</table>
<p:commandButton ajax="false" value="Update Question" action="#{editBean.updateQuestionAction}"
rendered="#{editBean.operation eq 'edit'}" />
<p:commandButton ajax="false" value="Add Question" update="msgs listForm:listPanel" action="#{editBean.saveQuestion}"
rendered="#{editBean.operation eq 'add'}">
<p:collector value="#{editBean.editQuestion}"
addTo="#{editBean.editBeanList}" />
</p:commandButton>
<p:commandButton ajax="false" value="Delete Question" update="msgs listForm:listPanel" action="#{editBean.deleteQuestionAction}"
rendered="#{editBean.operation eq 'edit'}">
<p:collector value="#{editBean.editQuestion}"
removeFrom="#{editBean.editBeanList}" />
</p:commandButton>
</h:form>
</p:panel>
</p:layoutUnit>
</p:tab>
Its not getting executing when i click on button
#ManagedBean
#RequestScoped
public class EditBean {
#ManagedProperty(value = "#{questionDao}")
private QuestionDao questionDao;
private String operation;
private QuestionHelper editQuestion;
private SelectItem[] linkedQuestionIds;
private List<QuestionHelper> linkedQuestions = new ArrayList<QuestionHelper>();
private List<QuestionHelper> allQuestions = new ArrayList<QuestionHelper>();
public void editQuestionAction() {
operation = "edit";
}
public void deleteQuestionAction() {
questionDao.delete(editQuestion.getQuestion());
listBean.getListOfQuestions().remove(editQuestion);
addNewQuestionAction();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Deleted !"));
}
public void updateQuestionAction() {
editQuestion.getQuestion().getOptionses().clear();
for (Options o : editQuestion.getOptions()) {
o.setQuestions(editQuestion.getQuestion());
editQuestion.getQuestion().getOptionses().add(o);
}
getQuestionDao().update(editQuestion.getQuestion());
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Question: ", "Question Updated !"));
}
Hi I found answer for my question, The command button is not working because of rendered tag and Request scope of managed bean , as on every subsequent request after pressing command button my request scoped (iseditable ) is getting resetting. When i made it Session scoped its working Fine.