Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

setActionListener on a4j:support does not execute the bean method

843844Nov 26 2008 — edited Nov 25 2009
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().createMetho
dBinding("#{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

Comments

843844
What is your reasoning for creating these objects programatically instead of using tags? This is a much more difficult way of adding components and should normally only be done if there is a good reason.
843844
Actually I have to write an AJAX enabled component that other users in my company will use. Otherwise I will have to give them a set of jsps. Now these jsps are more or less same for each applications so it will be a copy paste thing for each time. So basically this component will be replacement for all these jsp files. Writing a single composite custom component for all these jsps is the only way I can think of.

Anyway thanks for your time.

Thanks
Ahsan

Edited by: AhsanJaved on Nov 26, 2008 7:30 PM
843844
Hey Ahsan

Did you figure out how to get the a4j action to invoke the bean. I have the same problem. Any help would be highly appreciated.

Thank you
PhHein
Welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

I'm locking this thread now.
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 23 2009
Added on Nov 26 2008
4 comments
223 views