![](/img/trans.png)
[英]Custom JSF component renderer: how to render HTML around another element
[英]How to construct and invoke JSF component render from custom renderer
我正在實現自定義JSF組件渲染器(即org.primefaces.component.messages.MessageRenderer
),並希望在用戶單擊消息時添加要打開的輸出新對話框。
我明白我可以手動在encodeEnd
方法中添加所有需要的HTML / CSS / JS,但是因為我們已經有了Dialog組件,所以它會很浪費。
我的問題是:如何以編程方式構造和添加輸出新的JSF組件(在我的情況下對話框)? 我假設我們可以通過指定適當的屬性使其與現有元素進行交互。
事實證明這很容易:
Dialog dialog = new Dialog();
dialog.setModal(true);
// .. other parameters
dialog.encodeAll(context);
但我已經使用jqueryUI對話框組件(你需要單獨包含javascript到你的頁面)
String id = "someUniqueId";
writer.startElement("div", null);
writer.writeAttribute("id", id, null);
// ... content of dialog and command link to open dialog by id
writer.endElement("div");
writer.write("<script>$('#" + id + "').dialog("{resizable : false, autoOpen: false, modal: true});\n" +
"$('#" + id + "').parent('.ui-dialog').css('z-index', 2000);</script>");
因為在PrimeFaces中顯示嵌套的模態對話框並不容易。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.