0

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..

Mr Lister
  • 45,515
  • 15
  • 108
  • 150

1 Answers1

0

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>
Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555