Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Response Writer in jsf

Tags:

java

jsf

ResponseWriter writer=context.getResponseWriter();

I want to know about startElement, endElement, and writeAttribute methods on ResponseWriter.

like image 386
Warrior Avatar asked Jan 13 '09 05:01

Warrior


1 Answers

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.

like image 96
sblundy Avatar answered Nov 13 '22 15:11

sblundy