在父窗口中,我有一个列表和两个commandButton
commandButton
将在表格中添加新记录。当用户点击此按钮时,将打开一个弹出窗口,用户将给出值,提交列表将再次呈现,并且将添加新记录。commandButton
用户可以通过单击此commandbutton
来编辑添加的记录,以便在父窗口中进行编辑包含Popup像这样
< rich: panel id = "includePandel" > < ui: include src = "CfsGroupFeature-Add.xhtml" > < ui: param name = "parentBean"
value = "#{cfsBean}" / > < /ui:include>
</rich: panel >
这是Parent类中的Edit按钮,它将调用popup bean方法
action = "#{addFeaturePopUpBean.updateCfsGroupFeature(itemsComp,tableIndex.index)}"
这是整个命令
<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>
我在PopupBean或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);
}
}
}
}
}
到这里一切正常,我能够在弹出窗口中看到所选的行值。
现在在弹出窗口中,如果我点击保存按钮,然后commandButton
没有被调用,它只是重置(删除)预先填充的值。现在,如果我再次提交表格,那么它的工作。
注意: - 我正在使用相同的弹出窗口添加新记录和编辑..仅在我正在编辑时才会出现工作正常问题。
编辑: -
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
弹出源代码
<?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>