7 Replies Latest reply on Jan 4, 2009 12:13 AM by Peter Cheung

    actionListener In a4j:support Not Invoked

    Peter Cheung Newbie

      I was using v3.3.0.CR1, and I was trying to create a multi-level search criteria, based on the previous selection, different search criteria was displayed. The first level was a selectOneRadio button, and the second level could be either a selectOneMenu or selectOneRadio. Both levels were displayed fine. However, in the level2b (see code below), the actionListener "processProductClassInstanceValue" was not invoked at all (the a4j:support was executed, because I could see "isSecondLevelxxxDisplayable" & "isThirdLevelxxxDisplayable" were invoked) after the "productClassInstance2b" radio button was clicked. I wonder how come it was not invoked? The purpose of the actionListener "processProductClassInstanceValue" was to grab the value of the radio button and based on it "isThirdLevelxxxDisplayable" determine to display the third level or not. I wonder if this is the correct way of getting value from the radio button? I wonder how I am able to limit the rerendering to only inside outputPanel "inner3"(currently, I could see both "isSecondLevelxxxDisplayable" & "isThirdLevelxxxDisplayable" were invoked. Only methods applicable to "inner3" should be executed)? Thanks alot.

      <h:form id="searchCriteriaForm" accept="text/html" acceptCharset="UTF-8" enctype="UTF-8">
       <!-- Level 1 Begins -->
       <h:panelGrid id="level1" columns="5">
       <h:selectOneRadio value="#{usageDetailBean.billProductClassSelected}">
       <a4j:support event="onclick" actionListener="#{detailBean.processProductClassValue}" reRender="inner2" bypassUpdates="false"/>
       <f:selectItems value="#{detailBean.billProductClasses}"/>
       </h:selectOneRadio>
       </h:panelGrid>
       <!-- Level 1 Ends -->
       <!-- Inner 2 Begins -->
       <a4j:outputPanel id="inner2" layout="block">
       <h:panelGrid id="level2a" columns="5" rendered="#{detailBean.secondLevelInstanceDisplayable}">
       <h:graphicImage id="arrow2a" width="93" height="65" hspace="10" align="left" alt="" url="/images/arrow.gif" rendered="#{detailBean.secondLevelInstanceDisplayable}"/>
       <h:outputLabel for="instance2a" value="Select phone number" rendered="#{detailBean.secondLevelInstanceDisplayable}"/>
       <h:selectOneMenu id="instance2a" value="#{detailBean.serviceInstanceSelected}" rendered="#{detailBean.secondLevelInstanceDisplayable}">
       <f:selectItems value="#{detailBean.instanceItems}"/>
       </h:selectOneMenu>
       <br/><br/>
       <h:commandButton id="viewDetail2a" value="View details" action="nextPage" rendered="#{detailBean.secondLevelInstanceDisplayable}"/>
       </h:panelGrid>
       <!--/a4j:outputPanel-->
       <!--a4j:outputPanel id="inner2b" layout="block"-->
       <h:panelGrid id="level2b" columns="5" rendered="#{detailBean.secondLevelProductClassInstanceDisplayable}">
       <h:graphicImage id="arrow2b" width="93" height="65" hspace="10" align="left" alt="" url="/images/arrow.gif" rendered="#{detailBean.secondLevelProductClassInstanceDisplayable}"/>
       <h:outputLabel for="productClassInstance2b" value="Select phone number" rendered="#{detailBean.secondLevelProductClassInstanceDisplayable}"/>
       <h:selectOneRadio id="productClassInstance2b" value="#{detailBean.productClassServiceInstanceSelected}" rendered="#{detailBean.secondLevelProductClassInstanceDisplayable}">
       <a4j:support event="onclick" actionListener="#{detailBean.processProductClassInstanceValue}" reRender="inner3" bypassUpdates="false"/>
       <f:selectItems value="#{detailBean.productClassInstanceItems}"/>
       </h:selectOneRadio>
       <br/><br/>
       </h:panelGrid>
       </a4j:outputPanel>
       <!-- Inner 2 Ends -->
       <!-- Inner 3 Begins -->
       <a4j:outputPanel id="inner3" layout="block">
       <h:panelGrid id="level3" columns="5" rendered="#{detailBean.thirdLevelInstanceDisplayable}">
       <h:graphicImage id="arrow3" width="93" height="65" hspace="10" align="left" alt="" url="/images/arrow.gif" rendered="#{detailBean.thirdLevelInstanceDisplayable}"/>
       <h:outputLabel for="serviceInstance3" value="Select phone number" rendered="#{detailBean.thirdLevelInstanceDisplayable}"/>
       <h:selectOneMenu id="serviceInstance3" value="#{detailBean.serviceInstanceSelected}" rendered="#{detailBean.thirdLevelInstanceDisplayable}">
       <f:selectItems value="#{detailBean.instanceItems}"/>
       </h:selectOneMenu>
       <br/><br/>
       <h:commandButton id="viewDetail3" value="View details" action="nextPage" rendered="#{detailBean.thirdLevelInstanceDisplayable}"/>
       </h:panelGrid>
       </a4j:outputPanel>
       <!-- Inner 3 Ends -->
       <rich:messages/>
      </h:form>
      


        • 1. Re: actionListener In a4j:support Not Invoked
          Nick Belaevski Master

          Hello,

          Can you please add beans code? What are bean scopes?

          • 2. Re: actionListener In a4j:support Not Invoked
            Peter Cheung Newbie

            Here is the code of the backing-bean:

            public class DetailBean extends BaseBean implements Constants {
             public DetailBean() {
             super(DetailBean.class);
             log("about to execute c'tor");
             }
            
             /**
             * Instance variable to hold the returned BillDocument object of this bill.
             */
             public BillDocument getBillDocument() {
             return this.billDocument;
             }
             public void setBillDocument(BillDocument billDocument) {
             this.billDocument = billDocument;
             }
            
             public String getBillProductClassSelected() {
             return billProductClassSelected;
             }
             public void setBillProductClassSelected(String billProductClassSelected) {
             this.billProductClassSelected = billProductClassSelected;
             }
            
             public String getProductClassInstanceSelected() {
             return productClassInstanceSelected;
             }
             public void setProductClassInstanceSelected(String productClassInstanceSelected) {
             this.productClassInstanceSelected = productClassInstanceSelected;
             }
            
             public String getServiceInstanceSelected() {
             return serviceInstanceSelected;
             }
             public void setServiceInstanceSelected(String serviceInstanceSelected) {
             this.serviceInstanceSelected = serviceInstanceSelected;
             }
            
             public List<SelectItem> getBillProductClasses() {
             List<SelectItem> billProductClasses = new ArrayList<SelectItem>();
             if (billDocument.getBillProductClassSummaries() != null) {
             for (BillProductClassSummary productClassSummary:billDocument.getBillProductClassSummaries()) {
             if (!BUNDLE_PRODUCT_CLASS.equals(productClassSummary.getServiceInstanceClassCode())) {
             SelectItem item = new SelectItem();
             item.setLabel(productClassSummary.getDescription());
             item.setValue(Long.toString(productClassSummary.getId()));
             billProductClasses.add(item);
             }
             }
             }
             return billProductClasses;
             }
            
             public boolean isSecondLevelInstanceDisplayable() {
             logger.info("About to execute isSecondLevelInstanceDisplayable...");
             if ((billProductClassSelected == null) || (billProductClassSelected.trim().length() == 0))
             return false;
             logger.info("billProductClassSelected: " + billProductClassSelected);
            
             BillProductClassSummary billProductClassSummary = searchBillProductClassSummary(Long.parseLong(billProductClassSelected));
             logger.info("billProductClassSummary: " + billProductClassSummary);
             if ((billProductClassSummary.getBillProductClassServiceInstanceSummaries() == null) ||
             (billProductClassSummary.getBillProductClassServiceInstanceSummaries().isEmpty()))
             return false;
             else if (billProductClassSummary.getBillProductClassServiceInstanceSummaries().size() == 1) {
             logger.info("return true");
             return true;
             }
             else
             return false;
             }
            
             public boolean isSecondLevelBillProductClassInstanceDisplayable() {
             logger.info("About to execute isSecondLevelBillProductClassInstanceDisplayable...");
             if ((billProductClassSelected == null) || (billProductClassSelected.trim().length() == 0))
             return false;
             logger.info("billProductClassSelected: " + billProductClassSelected);
            
             BillProductClassSummary billProductClassSummary = searchBillProductClassSummary(Long.parseLong(billProductClassSelected));
             logger.info("billProductClassSummary: " + billProductClassSummary);
             if ((billProductClassSummary.getBillProductClassServiceInstanceSummaries() == null) ||
             (billProductClassSummary.getBillProductClassServiceInstanceSummaries().isEmpty()))
             return false;
             else if (billProductClassSummary.getBillProductClassServiceInstanceSummaries().size() == 1)
             return false;
             else {
             logger.info("return true");
             return true;
             }
             }
            
             public List<SelectItem> getProductClassInstanceItems() {
             List<SelectItem> productClassServiceInstanceItems = new ArrayList<SelectItem>();
             BillProductClassSummary billProductClassSummary = searchBillProductClassSummary(Long.parseLong(billProductClassSelected));
             if (billProductClassSummary.getBillProductClassServiceInstanceSummaries() != null) {
             for (BillProductClassServiceInstanceSummary productClassServiceInstanceSummary:billProductClassSummary.getBillProductClassServiceInstanceSummaries()) {
             SelectItem item = new SelectItem();
             item.setLabel(productClassServiceInstanceSummary.getDescription());
             item.setValue(Long.toString(productClassServiceInstanceSummary.getId()));
             productClassServiceInstanceItems.add(item);
             }
             }
             return productClassServiceInstanceItems;
             }
            
             public List<SelectItem> getInstanceItems() {
             List<SelectItem> thirdLevelItems = new ArrayList<SelectItem>();
             BillProductClassSummary billProductClassSummary = searchBillProductClassSummary(Long.parseLong(billProductClassSelected));
             if (billProductClassSummary.getBillProductClassServiceInstanceSummaries() != null) {
             for (BillProductClassServiceInstanceSummary productClassServiceInstanceSummary:billProductClassSummary.getBillProductClassServiceInstanceSummaries()) {
             SelectItem item = new SelectItem();
             item.setLabel(productClassServiceInstanceSummary.getBillServiceInstance().getPrimaryServiceResourceIdValue());
             item.setValue(Long.toString(productClassServiceInstanceSummary.getBillServiceInstance().getId()));
             thirdLevelItems.add(item);
             }
             }
             return thirdLevelItems;
             }
            
             public boolean isThirdLevelInstanceDisplayable() {
             logger.info("About to execute isThirdLevelInstanceDisplayable...");
             if ((productClassServiceInstanceSelected == null) || (productClassServiceInstanceSelected.trim().length() == 0)) {
             return false;
             }
            
            // BillProductClassServiceInstanceSummary billProductClassServiceInstanceSummary = searchBillProductClassServiceInstanceSummary(billDocument.getBillProductClassSummaries().get(2), Long.parseLong(input));
             BillProductClassServiceInstanceSummary billProductClassServiceInstanceSummary = searchBillProductClassServiceInstanceSummary(billDocument.getBillProductClassSummaries().get(Integer.parseInt(billProductClassSelected)), Long.parseLong(productClassServiceInstanceSelected));
             if (billProductClassServiceInstanceSummary == null)
             return false;
             else {
             logger.info("return true");
             return true;
             }
             }
            
             /**
             * This method invokes the BillDocumentService to retrieve the bill detail info.
             */
             public String getBillDetail() {
             logger.info("About to execute getBillDetail...");
             try {
             BillDocumentServiceIntf billDocumentService = (BillDocumentServiceIntf)getManagedBean(BILL_DOCUMENT_SERVICE);
             Response response = billDocumentService.getBillDocumentDetailCharges(billDocument);
             String messageKey = null;
             if (response.isSuccess()) {
             List<BillProductClassSummary> billProductClassSummaries =
             (List<BillProductClassSummary>)response.getResponse();
             billDocument.setBillProductClassSummaries(billProductClassSummaries);
             return USAGE_DETAIL_SUCCESS;
             }
             else {
             messageKey = (String)response.getStatus().getErrorKeys()[0];
             handleError(null, messageKey);
             return USAGE_DETAIL_FAILURE;
             }
             }
             catch (Exception e) {
             logger.error("Error in process the request", e);
             e.printStackTrace();
             return FAILURE;
             }
             }
            
             public void processProductClassValue(ActionEvent input) {
             logger.info("About to execute processProductClassValue...");
             HtmlAjaxSupport source = (HtmlAjaxSupport)input.getSource();
             HtmlSelectOneRadio radio = (HtmlSelectOneRadio) source.getParent();
             Object value = radio.getValue();
             billProductClassSelected = (String)value;
             logger.info("billProductClassSelected: " + billProductClassSelected);
             }
            
             public void processProductClassInstanceValue(ActionEvent input) {
             logger.info("About to execute processProductClassInstanceValue...");
             HtmlAjaxSupport source = (HtmlAjaxSupport)input.getSource();
             HtmlSelectOneRadio radio = (HtmlSelectOneRadio) source.getParent();
             Object value = radio.getValue();
             serviceInstanceSelected = (String)value;
             logger.info("serviceInstanceSelected: " + serviceInstanceSelected);
             }
            
             public void productClassInstanceChange(ValueChangeEvent event){
             logger.info("About to execute productClassInstanceChange...");
             HtmlSelectOneRadio radio = (HtmlSelectOneRadio)event.getComponent();
             String value = (String)radio.getValue();
             logger.info("value: " + value);
             }
            
             private BillProductClassSummary searchBillProductClassSummary(long id) {
             if ((billDocument.getBillProductClassSummaries() == null) ||
             (billDocument.getBillProductClassSummaries().isEmpty()))
             return null;
            
             boolean found = false;
             int idx = 0;
             List<BillProductClassSummary> billProductClassSummaries = billDocument.getBillProductClassSummaries();
             do {
             if (billProductClassSummaries.get(idx).getId() == id)
             found = true;
             else
             idx++;
             } while ((idx < billDocument.getBillProductClassSummaries().size()) && (!found));
            
             if (found)
             return billDocument.getBillProductClassSummaries().get(idx);
             else
             return null;
             }
            
             private BillProductClassServiceInstanceSummary searchBillProductClassServiceInstanceSummary(BillProductClassSummary billProductClassSummary, long id) {
             if ((billProductClassSummary.getBillProductClassServiceInstanceSummaries() == null) ||
             (billProductClassSummary.getBillProductClassServiceInstanceSummaries().isEmpty()))
             return null;
            
             boolean found = false;
             int idx = 0;
             do {
             if (billProductClassSummary.getBillProductClassServiceInstanceSummaries().get(idx).getId() == id)
             found = true;
             else
             idx++;
             } while ((idx < billProductClassSummary.getBillProductClassServiceInstanceSummaries().size()) && (!found));
            
             if (found)
             return billProductClassSummary.getBillProductClassServiceInstanceSummaries().get(idx);
             else
             return null;
             }
            
             /**
             * Attributes
             */
             private static final Logger logger = Logger.getLogger(UsageDetailBean.class);
            
             private BillDocument billDocument;
             private String billProductClassSelected;
             private String productClassInstanceSelected;
             private String serviceInstanceSelected;
            }
            


            Here is the definition of the bean in faces-bean-config.xml:
             <managed-bean>
             <managed-bean-name>detailBean</managed-bean-name>
             <managed-bean-class>com.xxx.web.bean.DetailBean</managed-bean-class>
             <managed-bean-scope>request</managed-bean-scope>
             <managed-property>
             <property-name>billDocumentService</property-name>
             <value>#{billDocumentServiceProxy}</value>
             </managed-property>
             </managed-bean>
            


            Thanks alot.

            • 3. Re: actionListener In a4j:support Not Invoked
              Peter Cheung Newbie

              I changed the scope of the backing-bean to "session", and the result was still the same...

              • 4. Re: actionListener In a4j:support Not Invoked
                Peter Cheung Newbie

                This is what I got from <a4j:log> when I clicked the radio button at "level2b":

                debug[11:35:19,171]: Have Event [object Object] with properties: target: undefined, srcElement: [object], type: click
                debug[11:35:19,171]: Query preparation for form 'searchCriteriaForm' requested
                debug[11:35:19,171]: Append hidden control searchCriteriaForm_SUBMIT with value [1] and value attribute [1]
                debug[11:35:19,171]: Append hidden control autoScroll with value [] and value attribute []
                debug[11:35:19,171]: Append hidden control javax.faces.ViewState with value [...]
                debug[11:35:19,171]: parameter searchCriteriaForm:j_id24 with value searchCriteriaForm:j_id24
                debug[11:35:19,171]: Look up queue with default name
                debug[11:35:19,171]: NEW AJAX REQUEST !!! with form: searchCriteriaForm
                debug[11:35:19,171]: Start XmlHttpRequest
                debug[11:35:19,171]: Reqest state : 1
                debug[11:35:19,187]: QueryString: AJAXREQUEST=searchCriteriaForm%3Aj_id18&searchCriteriaForm%3Aj_id14=3&searchCriteriaForm%3AproductClassServiceInstance2b=1&searchCriteriaForm_SUBMIT=1&autoScroll=&javax.faces.ViewState=...&searchCriteriaForm%3Aj_id24=searchCriteriaForm%3Aj_id24&
                debug[11:35:19,187]: Reqest state : 1
                debug[11:35:19,390]: Reqest state : 2
                debug[11:35:19,390]: Reqest state : 3
                debug[11:35:19,390]: Reqest state : 4
                debug[11:35:19,390]: Reqest end with state 4
                debug[11:35:19,390]: Response with content-type: text/xml;charset=UTF-8
                debug[11:35:19,390]: Full response content: <?xml version="1.0"?>
                <html xmlns="http://www.w3.org/1999/xhtml"><head><link class="component" href="/eBill/facelets/a4j/s/3_3_0.CR1org/richfaces/renderkit/html/css/basic_classes.xcss/DATB/eAGbo7-tNnT5DGkAEXoDrg__" rel="stylesheet" type="text/css" /><link class="component" href="/eBill/facelets/a4j/s/3_3_0.CR1org/richfaces/renderkit/html/css/extended_classes.xcss/DATB/eAGbo7-tNnT5DGkAEXoDrg__" media="rich-extended-skinning" rel="stylesheet" type="text/css" /><script src="/eBill/facelets/a4j/g/3_3_0.CR1org.ajax4jsf.javascript.AjaxScript" type="text/javascript">
                </script><script src="/eBill/facelets/a4j/g/3_3_0.CR1org/richfaces/renderkit/html/scripts/skinning.js" type="text/javascript">
                </script><meta name="Ajax-Update-Ids" content="" /><title></title></head><body><span id="ajax-view-state"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="..." /></span><meta id="Ajax-Response" name="Ajax-Response" content="true" /><!-- MYFACES JAVASCRIPT -->
                <script type="text/javascript"><!-- function getScrolling() {
                 var x = 0; var y = 0;if (self.pageXOffset || self.pageYOffset) {
                 x = self.pageXOffset; y = self.pageYOffset; }
                 else if ((document.documentElement && document.documentElement.scrollLeft)||(document.documentElement && document.documentElement.scrollTop))
                 { x = document.documentElement.scrollLeft;
                 y = document.documentElement.scrollTop; } else if (document.body) {
                 x = document.body.scrollLeft; y = document.body.scrollTop; }
                 return x + "," + y; } //--></script></body></html>
                debug[11:35:19,390]: Header Ajax-Expired not found, search in <meta>
                debug[11:35:19,390]: search for elements by name 'meta' in element #document
                debug[11:35:19,390]: Find <meta name='Ajax-Update-Ids' content=''>
                debug[11:35:19,390]: Find <meta name='Ajax-Response' content='true'>
                debug[11:35:19,390]: Header Ajax-Update-Ids not found, search in <meta>
                debug[11:35:19,390]: search for elements by name 'meta' in element #document
                debug[11:35:19,390]: Find <meta name='Ajax-Update-Ids' content=''>
                warn[11:35:19,390]: No information in response about elements to replace
                debug[11:35:19,390]: call selectSingleNode for id= org.ajax4jsf.oncomplete
                debug[11:35:19,390]: call selectSingleNode for id= ajax-view-state
                debug[11:35:19,390]: Hidden JSF state fields:
                debug[11:35:19,390]: Namespace for hidden view-state input fields is undefined
                debug[11:35:19,390]: search for elements by name 'input' in element span
                debug[11:35:19,390]: Replace value for inputs: 14 by new values: 1
                debug[11:35:19,406]: Input in response: javax.faces.ViewState
                debug[11:35:19,406]: Found same input on page with type: hidden
                debug[11:35:19,406]: Found same input on page with type: hidden
                debug[11:35:19,406]: Found same input on page with type: hidden
                debug[11:35:19,406]: search for elements by name 'INPUT' in element span
                debug[11:35:19,406]: Replace value for inputs: 14 by new values: 0
                debug[11:35:19,406]: call selectSingleNode for id= _A4J.AJAX.focus
                debug[11:35:19,406]: No focus information in response
                


                • 5. Re: actionListener In a4j:support Not Invoked
                  Nick Belaevski Master

                  And what is value of #{detailBean.secondLevelProductClassInstanceDisplayable} when you click 'level2b': false or true?

                  • 6. Re: actionListener In a4j:support Not Invoked
                    Nick Belaevski Master

                    P.S. Do you see that #{detailBean.processProductClassInstanceValue} action is invoked?

                    • 7. Re: actionListener In a4j:support Not Invoked
                      Peter Cheung Newbie

                      #{detailBean.secondLevelProductClassInstanceDisplayable} was false when 'level2b' was clicked.

                      #{detailBean.processProductClassInstanceValue} action was not invoked.

                      Thanks alot for the hint. Since my backing-bean was in request scope, all the input values entered prior were gone, so level2b was not supposed to be rendered, and it explained why the actionListener of "level2b" was not invoked. After I added the t:saveState to both billProductClassSelected & serviceInstanceSelected and the page worked!

                      Thanks once again.