Search code examples
jsfjsp-tags

Writing a custom JSF Tag


I am trying to write a custom tag. I can write attributes; however, I'm having difficulty writing the innerHTML part:

<span class="required">*</span>

I can write:

writer.startElement("span", component);
writer.writeAttribute("class", "required", "class");
writer.endElement("span");

How do I write the *?

http://developers.sun.com/docs/jscreator/apis/jsf/javax/faces/context/ResponseWriter.html

This is a simple example, essentially, I would like to wrap some other JSF components to simplify what goes into my xhtml file.

Thanks, Walter


Solution

  • As explained by digitalross, you can simply write text:

    writer.startElement("span", component);
    writer.writeAttribute("class", "required", "class");
    writer.writeText("*");
    writer.endElement("span");
    

    If you need to include another HTML tags (instead of text):

    writer.startElement("span", component);
    writer.writeAttribute("class", "required", "class");
    writer.startElement("xxx", component);
    ...
    writer.endElement("xxx");
    writer.endElement("span");