action invoked only after page refresh? - jsf
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.
Related
JSF Conditionally render errors in a row
I would like to render the errors in a separate row of this table. However, the binding doesn't work when I use the ui:repeat as it sets all rows to the same value. <ui:repeat id="quest" value="#{questions}" var="question"> <tr> <td class="col-md-2"> <p:selectOneRadio id="questionId" value="#{question.response}" binding="#{questionBinding}" validator="#{question.validate}" required="true" requiredMessage="You must answer the question to continue"> <f:selectItem itemLabel="Yes" itemValue="Yes" /> <f:selectItem itemLabel="No" itemValue="No" /> <p:ajax update="error-row" /> </p:selectOneRadio> </td> </tr> <h:panelGroup id="error-row"> <ui:fragment rendered="#{not empty facesContext.getMessageList(questionBinding.clientId)}"> <tr> <td colspan="2"><p:message for="questionId" id="msgQuestion" /></td> </tr> </ui:fragment> </h:panelGroup> </ui:repeat>
Call javascript on ajax update: .... <p:ajax update="msgQuestion" oncomplete="clearEmptyRows()" /> .... Using javascript function: <script> function clearEmptyRows() { $(".error-row").each(function(index) { if ($(this).text().trim() == '') { $(this).css("display", "none"); } else { $(this).css("display", "table-row"); } }); } $(document).ready(function() { clearEmptyRows(); }); </script>
Display Alert Message at run time in jsf
In following code Cheque Amount is less then (quautity * rate) then display alert message. XHTML code : <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:inputText id="description" value="#{invoiceBean.descriptionOfGoodsOrService}" cols="45" required="true" label="Description" requiredMessage="Description Require Entry" disabled="#{invoiceBean.descriptionOfGoodsOrService != null}" /></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> <h:panelGroup id="mode"> <p:panelGrid columns="2"> <p:panelGrid columns="2"> <p:outputLabel style="font-weight: bold;" value="Mode Of Payments" /> <p:selectOneRadio value="#{invoiceBean.modeOfPayment}" layout="pageDirection"> <f:ajax render="mode" /> <f:selectItem itemLabel="Cash" itemValue="Cash" /> <f:selectItem itemLabel="Cheque" itemValue="Cheque" /> </p:selectOneRadio> <p:outputLabel value="Enter Bank Name :" /> <p:inputText value="#{invoiceBean.bankName}" disabled="#{invoiceBean.modeOfPayment == 'Cash'}" /> <p:outputLabel value="Enter Cheque Number :" /> <p:inputText value="#{invoiceBean.chequeNumber}" disabled="#{invoiceBean.modeOfPayment == 'Cash'}" /> <p:outputLabel value="Total is :" /> <p:inputText value="#{invoiceBean.chequeAmount}" /> </p:panelGrid> <p:panelGrid columns="1"> <p:dataTable value="#{invoiceBean.transactions}" var="transaction"> <p:column headerText="Mode Of Payment"> <p:outputLabel value="#{transaction.modeOfPayment}" /> </p:column> <p:column headerText="Bank Name"> <p:outputLabel value="#{transaction.bankName}" /> </p:column> <p:column headerText="Amount"> <p:outputLabel value="#{transaction.chequeAmount}" /> </p:column> <p:column headerText="Balance"> <p:outputLabel value="#{transaction.balance}" /> </p:column> <p:summaryRow> <p:column colspan="3"> <p:outputLabel value="Remaining Balance" /> </p:column> <p:column> <p:outputLabel value="#{transaction.balance}" /> </p:column> </p:summaryRow> </p:dataTable> </p:panelGrid> </p:panelGrid> </h:panelGroup> <p:commandButton value="Save New Invoice" action="#{invoiceBean.addRow}" update=":form:invoiceTable growl" process="#form invoiceTable" onclick="PF('addInvoice').hide();"> <f:ajax render=":form:invoiceTable" /> </p:commandButton> <p:growl id="growl" showDetail="true" sticky="true" /> </p:dialog> Following managed bean code it is used to store transaction related data : public void addRow() { int lastBalance, currentBalance, storeBalance; transaction = new Transaction(); invoiceProductsServicesDetail = new InvoiceProductsServicesDetail(); invoiceDao = new InvoiceDao(); transactionDao = new TransactionDao(); FacesContext facesContext = FacesContext.getCurrentInstance(); DataTable dataTable = (DataTable) facesContext.getViewRoot().findComponent("form:invoiceTable"); UIComponent uiTable = ComponentUtils.findParentForm(facesContext,dataTable); final AjaxBehavior behavior = new AjaxBehavior(); try { amount = (rate * quantity); if(chequeAmount <= amount){ transactions = transactionDao.getTransactions(invoices.get(0).getId()); if (transactions.size() != 0) { setTransactions(transactions); lastBalance = transactions.get(transactions.size() - 1).getBalance(); } else { lastBalance = 0; } currentBalance = chequeAmount - amount; storeBalance = lastBalance + currentBalance; transaction.setModeOfPayment(modeOfPayment); if (modeOfPayment.equals("Cheque")) { transaction.setBankName(bankName); transaction.setChequeNumber(chequeNumber); transaction.setBalance(storeBalance); } else { transaction.setBalance(storeBalance); } transaction.setChequeAmount(chequeAmount); transaction.setReceiptNumber(String.valueOf(new Date().getTime())); transactionDao.setTransaction(transaction, invoices.get(0).getId()); this.transactions = transactionDao.getTransactions(invoices.get(0).getId()); RowEditEvent rowEditEvent = new RowEditEvent(uiTable, behavior, invoiceProductsServicesDetail); rowEditEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES); dataTable.broadcast(rowEditEvent); }else{ //Diplay Alert Message that "Producats/Services total amount Must greater than your cheque amount" } } } catch (AbortProcessingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Then after transaction data store otherwise not.
put In the else part FacesMessage facesMessage = new FacesMessage(); facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR); facesMessage.setDetail("Producats/Services total amount Must greater than your cheque amount"); FacesContext.getCurrentInstance().addMessage(null, facesMessage); return null;
onkeydown event triggering clicking a command button
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>
selectBooleanCheckBox does not work seperatly in p:dialog
I have button that when I click on it, the dialog appear and in that dialog , I have p:selectBooleanCheckBox and h:outputlable. The first problem is when p:dialog appear I can not choose p:selectBooleanCheckBox separately. It means that when I click on one of them, all of p:selectBooleanCheckBox choose. The second problem is when I click on p:commandButton in dialog , the actionListener work but it dos not disappaer and it shows permanently. I think the problem cause by Ajax. could you please tell me how can I fix this problem? <h:panelGrid> <p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg"> <h:panelGrid columns="1" id="display"> <p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" > <tr> <td> <p:selectBooleanCheckbox/> </td> <td> <h:outputLabel value="test"/> </td> </tr> </p:dataGrid> <p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}" actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}" update="display" /> </h:panelGrid> </p:dialog> </h:panelGrid> <table style="width: 100%" id="tabell"> <p:selectOneButton value="#{inviteRequestManagedBean.filterType}"> <f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" /> <f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" /> <f:ajax event="change" execute="#form" render="#form" /> <tr> <td> <p:panel></p:panel> <p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" > <p:column> <div> <table border="0" width="100%"> <tr> <td> <p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/> </td> <td> <div> <table border="0" width="100%"> <tr> <td> <h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/> </td> </tr> <tr> <td> <h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/> </td> </tr> </table> </div> </td> here is where p:dialog call <td> <p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}" onclick="dlg.show()" /> </td> <td> <p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}" actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}" update="#form" /> </td> <p:blockUI block="acceptCommonButton" trigger="acceptCommonButton"/> <p:blockUI block="noNowCommonButton" trigger="acceptCommonButton"/> <p:blockUI block="acceptCommonButton" trigger="noNowCommonButton"/> <p:blockUI block="noNowCommonButton" trigger="noNowCommonButton"/> <td> <p:panel> <p:ajaxStatus> <f:facet name="start"> <p:graphicImage value="../resources/img/loading.gif"/> </f:facet> <f:facet name="complete"> <h:outputLabel value=""/> </f:facet> </p:ajaxStatus> </p:panel> </td> </tr> </table> </div> <hr/> </p:column> </p:dataGrid> </td> </tr> </p:selectOneButton> </table> </h:panelGrid> <h:panelGrid> <p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg"> <h:panelGrid columns="1" id="display"> <p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.loadPartyRelationShipType()}" columns="1" > <tr> <td> <p:selectBooleanCheckbox/> </td> <td> <h:outputLabel value="test"/> </td> </tr> </p:dataGrid> <p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}" actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}" update="display" oncomplete="dlg.hide()" /> </h:panelGrid> </p:dialog> </h:panelGrid> </ui:composition>
Your markup is a bit scary, I don't get why you've got so much thing in your <p:selectOneButton (all the <tr>'s) so instead of trying to correct everything as I start to understand what you try to achieve I'll give you a working example. Sample.java public class Sample implements Serializable { private String name; private boolean checked; public Sample() { } public Sample(String name, boolean checked) { this.name = name; this.checked = checked; } // Getter and Setter for name and checked omitted } SampleBean.java #ManagedBean #ViewScoped public class SampleBean implements Serializable { private List<Sample> samples; private Sample currentSample; public void prepareEdit(Sample sample) { this.currentSample = sample; } public void edit() { // Do what you need to do with sample // You can get it with : this.currentSample RequestContext.getCurrentInstance().execute("dlg.hide()"); } public List<Sample> getSamples() { if (this.samples == null) { this.samples = new ArrayList<Sample>(); for (int i = 1; i <= 10; ++i) { this.samples.add(new Sample("Sample n°" + i, (i % 3 == 0))); } } return samples; } public void setSamples(List<Sample> samples) { this.samples = samples; } public Sample getCurrentSample() { return currentSample; } public void setCurrentSample(Sample currentSample) { this.currentSample = currentSample; } } view.xhtml : <h:form id="myForm"> <p:dataTable value="#{sampleBean.samples}" var="sample"> <p:column headerText="Name"> <h:outputText value="#{sample.name}" /> </p:column> <p:column headerText="Checked?"> <h:outputText value="#{sample.checked}" /> </p:column> <p:column style="width: 1px; text-align: center;"> <p:commandButton value="edit" actionListener="#{sampleBean.prepareEdit(sample)}" update=":dialog" oncomplete="dlg.show()" /> </p:column> </p:dataTable> </h:form> <p:dialog id="dialog" widgetVar="dlg" header="Editing"> <h:form rendered="#{!empty sampleBean.currentSample}"> <h:outputText value="Current sample is #{sampleBean.currentSample.name}" /> <br /> <p:selectBooleanCheckbox value="#{sampleBean.currentSample.checked}" /> <br /> <p style="width: 100%; text-align: center;"> <p:commandButton actionListener="#{sampleBean.edit()}" value="Edit" update="#form :myForm" /> </p> </h:form> </p:dialog> As you can see I'm storing a currentSample (sampleBean must be #ViewScoped) which helps me to render a custom dialog with the correct current information. My last comment from your question about the binding of the <p:selectBooleanCheckbox is important because you can get a custom checkbox value only if it's bound to a different endpoint based on the context (here currentSample). Don't hesitate to comment if something is unclear for you!
While using reRender, rendered object will not update without a page refresh
I have a h:selectonemenu that is populated by a list. When a specific value is selected, a h:datatable should be rendered. When I select that "specific" value, the h:datatable does not render until I refresh the page. What am I doing wrong? <tr class="portlet-table-body" > <td width="20%" class="porlet-padding-left"><h:outputText value="${operatorProgramBundle.NextGenerationWorkflow}" /></td> <td width="450px"> <h:selectOneMenu id="ngw" styleClass="portlet-dropdown" value="${CRUDOperatorProgram.selectedNextGenWorkflow}"> <f:selectItems value="${CRUDOperatorProgram.nextGenWorkflowList}" /> <a4j:support event="onchange" ajaxsingle = "true" reRender="customTable" ></a4j:support> </h:selectOneMenu> </td> </tr> <h:panelGroup id="customTable"> <h:dataTable id="DispatchConfigurationCustom" columnClasses="portlet-table-same portlet-table-cell" headerClass="portlet-table-same portlet-table-cell" value="#{CRUDOperatorProgram.workflowConfigList}" var="workflowConfig" width="100%" rendered="#{CRUDOperatorProgram.selectedNextGenWorkflow == 0}"> <h:column> <f:facet name="header"> <h:outputText value="Include" /> </f:facet> <h:selectBooleanCheckbox id="includeInd" value="#{workflowConfig.isIncludedInd}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Automate" /> </f:facet> <h:selectOneRadio id="onOff" value="#{workflowConfig.isAutomatedInd}"> <f:selectItem id="onButton" itemLabel="On" itemValue="0" /> <f:selectItem id="offButton" itemLabel="Off" itemValue="0" /> </h:selectOneRadio> </h:column> </h:dataTable> </h:panelGroup> Updated Code: <tr class="portlet-table-body" > <td width="20%" class="porlet-padding-left"><h:outputText value="${operatorProgramBundle.NextGenerationWorkflow}" /></td> <td width="450px"> <h:selectOneMenu id="ngw" styleClass="portlet-dropdown" value="#{CRUDOperatorProgram.selectedNextGenWorkflow}" valueChangeListener="#{CRUDOperatorProgram.nextGenWorkflowChanged}"> <f:selectItems value="#{CRUDOperatorProgram.nextGenWorkflowList}" /> <a4j:support event="onchange" reRender="customTable"></a4j:support> </h:selectOneMenu> </td> </tr> <h:panelGroup id="customTable"> <h:dataTable id="DispatchConfigurationCustom" columnClasses="portlet-table-same portlet-table-cell" headerClass="portlet-table-same portlet-table-cell" value="#{CRUDOperatorProgram.workflowConfigList}" var="workflowConfig" width="100%"> <h:column> <f:facet name="header"> <h:outputText value="Include" /> </f:facet> <h:selectBooleanCheckbox id="includeInd" value="#{workflowConfig.isIncludedInd}"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Automate" /> </f:facet> <h:selectOneRadio id="onOff" value="#{workflowConfig.isAutomatedInd}"> <f:selectItem id="onButton" itemLabel="On" itemValue="0" /> <f:selectItem id="offButton" itemLabel="Off" itemValue="0" /> </h:selectOneRadio> </h:column> </h:dataTable> </h:panelGroup> Back Bean (Relevant parts) ... private List<WorkflowConfig> workflowConfigList = new ArrayList<WorkflowConfig>(); private List<SelectItem> nextGenWorkflowList; public void nextGenWorkflowChanged(ValueChangeEvent event) { workflowConfigList.clear(); //the value is a long, so make it a string and check if(event.getNewValue() != null && event.getNewValue().toString().equals("0")){ loadWorkFlowConfigs(); }else{ //Do not show the datatable workflowConfigList.clear(); } } public List<WorkflowConfig> getWorkflowConfigList(){ return this.workflowConfigList; } private void loadWorkFlowConfigs() { Query query = em.createNamedQuery("findAllWorkflowSteps"); List<WorkflowStep> step = (List<WorkflowStep>) query.getResultList(); for(WorkflowStep workflowStep : step){ WorkflowConfig workflowConfig = new WorkflowConfig(); workflowConfig.setWorkflowStep( workflowStep ); workflowConfigList.add(workflowConfig); } } I implemented a valueChangeListener like you said. I tried this example (with the h:panelGroup) and the example without a h:panelGroup explained in the documentation. Each require a page refresh... Can you see anything I'm doing wrong?
Change the behavior of the <a4j:support> component by adding adding the action=#{someBean.someMethod} tag attribute or add a valueChangeListener in your <h:selectOneMenu>. IMO, I preffer to add a valueChangeListener. See the example in the official documentation. As a side note, why you use ${...} instead of #{...}?