logo
down
shadow

Cannot invoke listener method from f:ajax inside composite component


Cannot invoke listener method from f:ajax inside composite component

By : Prince Of Heart
Date : November 14 2020, 04:48 PM
With these it helps This is my composite component hc:rangeChooser: , Firstly,
code :
<cc:clientBehavior ... targets="#{cc.clientId}:datetype" />
<cc:clientBehavior ... targets="datetype" />
<f:ajax ... update=":form:growl" />
<f:ajax ... render=":form:growl" />


Share : facebook icon twitter icon
JSF 2 - How can I add an Ajax listener method to composite component interface?

JSF 2 - How can I add an Ajax listener method to composite component interface?


By : user3220678
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , I have a JSF 2 composite component that employs some Ajax behavior. I want to add a listener method to the tag inside my composite component, but the listener method should be provided as a in the . , If you can get rid of the AjaxBehaviorEvent argument,
code :
public void genericAjaxEventLogger() {
    // ...
}
<cc:attribute name="ajaxEventListener" method-signature="void listener()" />
<cc:attribute name="ajaxEventListener" method-signature="void listener(javax.faces.event.AjaxBehaviorEvent)" />
<f:ajax listener="#{cc.attrs.ajaxEventListener}" />
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
<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>
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 });
    }

}
JSF 2 -- Composite component with optional listener attribute on f:ajax

JSF 2 -- Composite component with optional listener attribute on f:ajax


By : tien
Date : March 29 2020, 07:55 AM
I hope this helps . You need to specify the method-signature attribute of the tag in order to treat the attribute value as a method expression. You can use the JSTL view build time tag to conditionally add the tag.
code :
<cc:interface>
    <cc:attribute name="listener" method-signature="void listener()" />
</cc:interface>
<cc:implementation>
    <h:someComponent>
        <c:if test="#{cc.getValueExpression('listener') != null}">
            <f:ajax listener="#{cc.attrs.listener}" />
        </c:if>
    </h:someComponent>
</cc:implementation>
<my:someComposite listener="#{bean.listener}" />
@FacesComponent("someComponent")
public class SomeComponent extends UINamingContainer {

    public boolean isHasListener() {
        return getValueExpression("listener") != null;
    }

}
<cc:interface type="someComponent">
    <cc:attribute name="listener" method-signature="void listener()" />
</cc:interface>
<cc:implementation>
    <h:someComponent>
        <c:if test="#{cc.hasListener}">
            <f:ajax listener="#{cc.attrs.listener}" />
        </c:if>
    </h:someComponent>
</cc:implementation>
Ajax attached to Composite Component updates model but does not fire listener

Ajax attached to Composite Component updates model but does not fire listener


By : Sugeetha Subbarayalu
Date : March 29 2020, 07:55 AM
will help you This may have to do with the "readonly" attribute set to true. Though you manage to send the change-event by hand (JS), the server-side processing of the listener may be dropped due to the readonly state. See e.g. jsf (richfaces) readonly input text validation.
f:ajax listener with arguments not working with composite component

f:ajax listener with arguments not working with composite component


By : Tunnel Ddos Protecti
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The runs during view build time and therefore the paragraph and field variables are only available during view build time. They are not available during component tree visit nor during view render time. The ajax action listener method is determined during a JSF component tree visit, not during view build time and hence the parameters will always resolve null.
If you replace by (and ensure that you're using the newest Mojarra version wherein all peculiar issues are been resolved), and put the bean in the view scope while keeping the getters free of business logic, then it should work fine.
Ajax listener method to composite component javax.faces.FacesException: Unable to find attribute in top level component

Ajax listener method to composite component javax.faces.FacesException: Unable to find attribute in top level component


By : asker
Date : March 29 2020, 07:55 AM
around this issue Ok the solution to this problem was actually very simple. I made a test case and everything was of course working fine, which this case even more frustrating.
The first thing i noticed that setting the required attribute to true, resulted in everything working fine.
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org