我想问你们所有人是否有可能动态获取存在JSF代码的元素ID。
我的意思是fx。:
<p id="paragraph1" class="textToEdit">#{paragraphBean.getParagraphTextById("paragraph1")}</p>
在这行代码中,我不想在JSF代码中编写“paragraph1”,而是希望从<p>
ID元素中提取它。
提前感谢您的所有回复..
答案 0 :(得分:0)
这仅适用于JSF组件,而不适用于纯HTML元素。 JSF将推动&#34; current component&#34;在EL范围内为#{component}
。
<h:someComponent id="foo">#{bean.foo(component.id)}</h:someComponent>
最好的办法是将样板重构为custom tagfile。
<my:p id="paragraph1" styleClass="textToEdit" />
/WEB-INF/tags/p.xhtml
的实施方式如下。
<p id="#{id}" class="#{styleClass}">#{paragraphBean.getParagraphTextById(id)}</p>