Question

When trying to dynamically set the event of an a4j:ajax as follow:

<a4j:ajax event="#{myBean.event}" listener="#{myBean.listener}" />

I get the following error:

<a4j:ajax> The 'event' attribute for behavior tag must be a literal

It seems to come from javax.faces.view.facelets.BehaviorHandler:

public BehaviorHandler(BehaviorConfig config) {
    super(config);
    this.behaviorId = config.getBehaviorId();
    this.event = this.getAttribute("event");
    if (null != event && !event.isLiteral()) {
        throw new TagException(this.tag, "The 'event' attribute for behavior tag must be a literal");
    }
}

I would like to write my own CustomBehaviorHandler to make it behave as I need. The question is: how to register this new CustomBehaviorHandler with JSF?

Or is there any other way to suit my needs?

I can't find any example nor documentation about it, but it seems to be possible, since PrimeFaces has its own org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.

Était-ce utile?

La solution

I would like to write my own CustomBehaviorHandler to make it behave as I need. The question is: how to register this new CustomBehaviorHandler with JSF?

You'd need to create a custom tag for that. Prepare a *.taglib.xml as demonstrated in this answer: Custom Facelet component in JSF (note: taghandler class is not necessary) and add the following entry:

<tag>
    <tag-name>ajax</tag-name>
    <behavior>
        <behavior-id>com.example.MyAjaxBehavior</behavior-id>
        <handler-class>com.example.MyAjaxBehaviorHandler</handler-class>
    </behavior>
    <!-- Define attributes here. -->
</tag>

Then you'll be able to use <my:ajax>. Note: you've got to reimplement a lot in the behavior handler class; you can't simply extend from BehaviorHandler as it throws the exception during its construction already.


Or is there any other way to suit my needs?

Depends on concrete functional requirement for which you thought that this would be the solution. This is unfortunately not stated anywhere in the question, so I can't answer that part.


I can't find any example nor documentation about it, but it seems to be possible, since PrimeFaces has its own org.primefaces.component.behavior.ajax.AjaxBehaviorHandler.

That's the <p:ajax>. The <a4j:ajax> which you've initially at your hands is also such one, by the way.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top