ResponseWriter writer=context.getResponseWriter();
I want to know about startElement, endElement, and writeAttribute methods on ResponseWriter.
JSF output is HTML/XML and a ResponseWriter makes it easier to generate it correctly. Say you wanted to render some text in a <span> tag.
<span>My random text</span>
The code would look like:
ResponseWriter writer=context.getResponseWriter();
writer.startElement("span", component);
writer.writeText(text, null);
writer.endElement("span");
writerAttribute comes in when you need to add an ID or class attribute to the tag.
ResponseWriter writer=context.getResponseWriter();
writer.startElement("span", component);
writer.writeAttribute("id", id, null);
writer.writeText(text, null);
writer.endElement("span");
This would render:
<span id="myId">My text</span>
Note: writeAttribute immediately follows startElement. Once you start another element or write some text, you cannot call writeAttribute.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With