Subodh Joshi
Subodh Joshi

Reputation: 13482

action invoked only after page refresh?

In a Parent Window i have a List and two commandButton

  1. 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 .
  2. 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 &lt; 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!=="" &amp;&amp; dependentValue.value!== "" ){
                if( valueType.value &lt; 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!=="" &amp;&amp; dependentValue.value!== "" ){
               if( valueType.value &lt; 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!=""  &amp;&amp; defavlue1.value!=""){
            if(allowed2.value == "Integer" || allowed2.value == "String"){
                for(var j=0; j &lt; 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!=="" &amp;&amp; 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!=="" &amp;&amp; maxval.value!==""){
                    if(allowed2.value == "Integer"){
                        if(defavlue1.value &lt; minval.value || defavlue1.value &gt; 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 &lt; minval.value || defavlue1.value.length &gt; 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>

Upvotes: 0

Views: 1431

Answers (1)

Paszek
Paszek

Reputation: 156

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.

Upvotes: 1

Related Questions