Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6061285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:55:15+00:00 2026-05-23T08:55:15+00:00

I have a JSF 2 composite component that employs some Ajax behavior. I want

  • 0

I have a JSF 2 composite component that employs some Ajax behavior. I want to add a listener method to the <f:ajax> tag inside my composite component, but the listener method should be provided as a <composite:attribute> in the <composite:interface>.

The <f:ajax> tag inside my composite component is currently hard-coded to a listener like this:

<f:ajax
    event="valueChange"
    execute="@this"
    listener="#{controller.genericAjaxEventLogger}"
    render="#{cc.attrs.ajaxRenderTargets}" />

The listener method on the bean has this signature:

public void genericAjaxEventLogger(AjaxBehaviorEvent event) 
        throws AbortProcessingException {
    // implementation code...
}

I want the composite component to be something like this so the page can supply its own event method, but I can’t figure out the correct syntax for the interface.

<f:ajax
    event="valueChange"
    execute="@this"
    listener="#{cc.attrs.ajaxEventListener}"
    render="#{cc.attrs.ajaxRenderTargets}" />

How can I do this?

UPDATED WITH SOLUTION:

I took the approach suggested by BalusC and it works great. The relevant snippets are:

The interface declaration in the composite component

<composite:interface>
    <composite:attribute
        name="myattributeUpdatedEventListener"
        method-signature="void listener()"
        required="true" />
    ...
</composite:interface>

The Ajax tag used in my composite component

<f:ajax
    event="valueChange"
    execute="@this"
    listener="#{cc.attrs.myattributeUpdatedEventListener}"
    render="#{cc.attrs.ajaxRenderTargets}" />

The place in my page where I use the composite component

<h:form>
    <compcomp:myCompositeComponent
        myattributeUpdatedEventListener="#{myBackingBean.updatedEventListenerXYZ}" />
</h:form>

And the method on my backing bean

public void updatedEventListenerXYZ() {
    // do something here...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:55:15+00:00Added an answer on May 23, 2026 at 8:55 am

    If you can get rid of the AjaxBehaviorEvent argument,

    public void genericAjaxEventLogger() {
        // ...
    }
    

    then you can use

    <cc:attribute name="ajaxEventListener" method-signature="void listener()" />
    

    If the argument is mandatory (for logging?), then you need to re-specify the attribute as follows

    <cc:attribute name="ajaxEventListener" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)" />
    

    However, this does here not work as expected with

    <f:ajax listener="#{cc.attrs.ajaxEventListener}" />
    

    on GF 3.1 + Mojarra 2.1.1:

    SEVERE: javax.faces.FacesException: wrong number of arguments
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalArgumentException: wrong number of arguments
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at com.sun.el.parser.AstValue.invoke(AstValue.java:234)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
        at com.sun.faces.facelets.el.ContextualCompositeMethodExpression.invoke(ContextualCompositeMethodExpression.java:177)
        at com.sun.faces.facelets.tag.TagAttributeImpl$AttributeLookupMethodExpression.invoke(TagAttributeImpl.java:450)
        at com.sun.faces.facelets.tag.jsf.core.AjaxBehaviorListenerImpl.processAjaxBehavior(AjaxHandler.java:447)
        at javax.faces.event.AjaxBehaviorEvent.processListener(AjaxBehaviorEvent.java:113)
        at javax.faces.component.behavior.BehaviorBase.broadcast(BehaviorBase.java:102)
        at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:760)
        at javax.faces.component.UICommand.broadcast(UICommand.java:300)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
        ... 28 more
    

    I’m not sure if this is a bug or not. For that I’d need to invest some more time to naildown it. However, it was workaroundable by creating a backing component which gets the MethodExpression from the attributes and invokes with the right number of arguments. Here’s a complete kickoff example:

    <ui:component 
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:cc="http://java.sun.com/jsf/composite"
        xmlns:ui="http://java.sun.com/jsf/facelets"
    >
        <cc:interface componentType="testCC">
            <cc:attribute name="ajaxEventListener" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)" />
        </cc:interface>
        <cc:implementation>
            <h:commandButton value="Submit">
                <f:ajax listener="#{cc.ajaxEventListener}" />
            </h:commandButton>
        </cc:implementation>
    </ui:component>
    

    with

    package com.example;
    
    import javax.el.MethodExpression;
    import javax.faces.component.FacesComponent;
    import javax.faces.component.UINamingContainer;
    import javax.faces.context.FacesContext;
    import javax.faces.event.AjaxBehaviorEvent;
    
    @FacesComponent(value="testCC")
    public class TestCC extends UINamingContainer {
    
        public void ajaxEventListener(AjaxBehaviorEvent event) {
            FacesContext context = FacesContext.getCurrentInstance();
            MethodExpression ajaxEventListener = (MethodExpression) getAttributes().get("ajaxEventListener");
            ajaxEventListener.invoke(context.getELContext(), new Object[] { event });
        }
    
    }
    

    Regardless, I believe that the backing component puts doors open for new ways to achieve the functional requirement you have had in mind anyway 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a composite component in JSF 2..., inside it I have defined a
I want to implement some javas cript into my JSF composite component, but I
I have a jsf component that must access to a javascript file, i added
I have a simple JSF 2.0 composite component example. <!DOCTYPE html PUBLIC -//W3C//DTD XHTML
I want to have a component that looks like a button, but instead of
I have a JSF page on which I want to have a checkbox that,
I have a JSF 2.0 composite component as follows: <composite:interface> <composite:attribute name=id/> <composite:attribute name=action1
I have a JSF form that consists of a grid and some detail fields.
A pretty normal case: We have a 'portlet' composite component that has two states:
I have a problem using <pre> tag inside <td> . I have JSF datatable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.