0
votes

I wanted to ask you all if there is a possibility to dynamically get the element ID in which JSF code exists.

What I mean by that is fx.:

    <p id="paragraph1" class="textToEdit">#{paragraphBean.getParagraphTextById("paragraph1")}</p>

In this line of code instead of me writing "paragraph1" in the JSF code I want it to be pulled from the <p> ID element.

Thanks in advance for all of your responses..

1

1 Answers

0
votes

That's only possible on JSF components, not on plain HTML elements. JSF will push the "current component" as #{component} in EL scope.

<h:someComponent id="foo">#{bean.foo(component.id)}</h:someComponent>

Your best bet is refactoring the boilerplate into a custom tagfile.

<my:p id="paragraph1" styleClass="textToEdit" />

Where /WEB-INF/tags/p.xhtml is implemented as below.

<p id="#{id}" class="#{styleClass}">#{paragraphBean.getParagraphTextById(id)}</p>