當試圖動態設置a4j:ajax
的event
如下:動態設置的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。
哇,你是對的,比我想象的要難...其實,我發現.xhtml文件變得很快被超載。我想嘗試[Java管理的視圖](http://pastebin.com/VqWHFSxi)。然後,在JSF bean中,只需[實例化一個新的視圖](http://pastebin.com/GgnmRMwp),並使用[自定義標籤](http://pastebin.com/L8b2bBRc),寫[只有幾行] (http://pastebin.com/7PKHku1M).xhtml文件中。但它似乎有點烏托邦,我不確定這樣一個系統的好處(它實際上更多的是關於技術挑戰;)所以,如果你有任何線索......無論如何,謝謝! – sp00m
我明白了。如果你走這條路,你可以通過'ClientBehaviorHolder#addClientBehavior(String,AjaxBehavior)'以編程方式添加它們。 – BalusC