0
我在Mojarra 2.2.13上,我的項目使用PrimeFaces 6.0。未使用addComponentResource呈現的JSF資源(JavaScript)
我正在寫我自己的JSF UIComponent
。它需要一些位於webapp/resources/js/charts.min.js
的JavaScript。當我使用@ResourceDependency
劇本呈現是標註我的組件:
@ResourceDependency(name = "js/charts.min.js", target = "head")
但是,我並不總是需要它來呈現。所以我想有條件的組件資源從encodeBegin(FacesContext context)
方法中添加視圖根:
if (condition) {
UIOutput js = new UIOutput();
js.setRendererType("javax.faces.resource.Script");
js.getAttributes().put("name", "js/charts.min.js");
context.getViewRoot().addComponentResource(context, js, "head");
writer.startElement("div", null);
writer.writeAttribute("class", "myChart", null);
// ... write chart data
writer.endElement("div");
}
這並沒有渲染腳本(myChart
是雖然呈現)。我的日誌中沒有出現錯誤。任何想法我可以檢查或改進?
我也測試沒有PrimeFaces(不知道它的頭渲染器是否造成這種情況),但結果是一樣的。
你嘗試了 JSTL標籤而不是Java代碼的設置? –
@ TheBitman no。創建UIComponent時有什麼用處? –
我想也許你可以在JSF文件而不是組件中過濾js LINK。但說實話我完全不明白你的問題:) –