6 Replies Latest reply on Nov 26, 2008 10:18 AM by Ahsan Javed

    setActionListener on a4j:support does not execute the bean m

    Ahsan Javed Newbie

      Hi,
      I have been trying to execute setActionListener method of HtmlAjaxSupport programatically. I can see that AJAX call is getting submitted to server, but somehow the method binding I have for setActionListener is not getting invoked. I am getting nuts for it. Please help me. Here is the code snippet I am using

      public void includeCheckBox(FacesContext context, int rowIndex) throws IOException {
       HtmlSelectBooleanCheckbox checkBox = new HtmlSelectBooleanCheckbox();
       checkBox.setId("checkBox_" + rowIndex);
       HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
       ajaxSupport.setEvent("onchange");
       ajaxSupport.setReRender(getJSFComponentId(context, "checkBox_" + rowIndex, "reportCube"));
       ajaxSupport.setActionListener(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{xmlolapReportBean.addPivotRow}", new Class[]{ActionEvent.class}));
       checkBox.getChildren().add(ajaxSupport);
       checkBox.setParent(this);
       RendererUtils.renderChild(context, checkBox);
       }
      


      Here are the helper methods

      public String getJSFComponentId(FacesContext context, String id, String parentId) {
       return getJSFComponentPrefix(context, parentId) + id;
       }
      
       public String getJSFComponentPrefix(FacesContext context, String parentId) {
       int parentIdIndex = getClientId(context).indexOf(parentId);
       if (parentIdIndex == -1) {
       throw new RuntimeException("No parent id found for the component.");
       }
       return getClientId(context).substring(0, parentIdIndex);
       }
      
      


      And here is the bean's method I have bound to setActionListener
      public void addPivotRow(ActionEvent event) {
       System.out.println("Hello ActionListener. I got you. Hurray!!!");
       }
      


      I am not able to execute this addPivotRow method when the checkBox's onchange event is called although the browser makes an Ajax request to server. I have verified it using firebug.

      Also please let me know how can I get setReRenderMethod work using this programatic approach instead of usual jsp tag approach.

      Thanks
      Ahsan