I have 2 elements, banana and an outputText, where banana is a custom JSF component and in banana renderer, I would like to generate HTML enclosing the specified element.
xhtml:
<h:outputText id="theApple" value="This is an Apple" />
.
.
.
<my:banana for="theApple" link="http://www.banana.com" />
bananaRenderer(encloses the target element in anchor links):
@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
ResponseWriter responseWriter = context.getResponseWriter();
Banana banana = Banana.class.cast(component);
responseWriter.startElement("a", null);
responseWriter.writeAttribute("id", banana.getClientId(context), null);
responseWriter.writeAttribute("href", banana.getLink(), null);
}
@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
ResponseWriter responseWriter = context.getResponseWriter();
Banana banana = Banana.class.cast(component);
responseWriter.endElement("a");
}
What I want to achieve:
<a href="http://www.banana.com">This is an Apple</a>
.
.
.
As you can see I want to encode not on the banana component but on the element it targets using "for" attribute. The closest example I saw is PrimeFaces tooltip, but I can't quite grasp how it utilizes the "for" attribute. http://www.primefaces.org/showcase/ui/overlay/tooltip/tooltipOptions.xhtml#
If someone can point me to the right direction, it would really be appreciated. Thank you.