2013-08-29 23 views
1

当试图动态设置a4j:ajaxevent如下:动态设置的A4J的事件:AJAX

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

我收到以下错误:

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

它似乎来自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"); 
    } 
} 

我想写我自己的CustomBehaviorHandler以使其表现符合我的需要。问题是:如何使用JSF注册这个新的CustomBehaviorHandler

或者还有其他方法可以满足我的需求吗?

我找不到任何示例或文档,但它似乎是可能的,因为PrimeFaces有它自己的org.primefaces.component.behavior.ajax.AjaxBehaviorHandler

回答

2

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?

您需要为此创建自定义标签。准备一个*.taglib.xml在这个答案证明:Custom Facelet component in JSF(注:taghandler类是没有必要的),并添加以下条目:

<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> 

然后你就可以使用<my:ajax>。注意:你必须在行为处理器类中重新实现;你不能简单地从BehaviorHandler延伸,因为它已经在建造期间抛出异常。


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.

这就是<p:ajax>。顺便说一下,你最初掌握的<a4j:ajax>也是这样。

+0

哇,你是对的,比我想象的要难...其实,我发现.xhtml文件变得很快被超载。我想尝试[Java管理的视图](http://pastebin.com/VqWHFSxi)。然后,在JSF bean中,只需[实例化一个新的视图](http://pastebin.com/GgnmRMwp),并使用[自定义标签](http://pastebin.com/L8b2bBRc),写[只有几行] (http://pastebin.com/7PKHku1M).xhtml文件中。但它似乎有点乌托邦,我不确定这样一个系统的好处(它实际上更多的是关于技术挑战;)所以,如果你有任何线索......无论如何,谢谢! – sp00m

+0

我明白了。如果你走这条路,你可以通过'ClientBehaviorHolder#addClientBehavior(String,AjaxBehavior)'以编程方式添加它们。 – BalusC