Thursday April 14, 2005 I first wrote the following at the end of my previous blog entry a couple of minutes ago. However, since that was a long blog on JavaScript, I figured those of you not interested in JavaScript would miss it, so I decided to move the following into this separate blog entry instead.
Essentially (read the older blog entry if you're interested in the details)
the Output Text component has an Escape property you can turn off
(it's on by default) which causes < to be emitted as < in the HTML.
You can use this to passthrough ANY HTML to your page. Please make sure
that it's valid XHTML though. This can be useful if you have some data on
the server you want to format nicely for the user; for example, you can generate
a table this way. Bind your output text to #{Page1.tableHtml}
and then put this in your page bean:
public String getTableHtml() {
StringBuffer sb = new StringBuffer();
sb.append("<table>"); // Add \n if you want resulting HTML to be more readable
for (int i = 0, n = result.size(); i < n; i++) {
sb.append("<tr>");
// Render your cells for result object i here
Foo foo = (Foo)result.get(i);
sb.append("<td>"); sb.append(foo.getName()); sb.append("</td>");
sb.append("<td>"); sb.append(foo.getAddress()); sb.append("</td>");
sb.append("</tr>");
}
sb.append("</table>");
return sb.toString();
}
The code is hopefully pretty self explanatory but the idea here is that on the server you have some list of objects you want to display, and for some reason, you can't use the preferred method of showing this in a JSF data table. Now you can dynamically create the HTML right into your page from the server-side.
You can obviously go way overboard with this facility. If you want to be really extreme, each one of your pages can have just a single Output Text component, bound to a property, and then you compute the entire page HTML contents in your page bean. But don't do that - in addition to the reduced designtime help (WYSIWYG) you'll miss out on all the automation in generating HTML JSF is providing for you. Over time the HTML emitted by the JSF components will get more complicated and advanced. And JSF components have an abstraction where the "rendering" is separate from the component, so your pages can render both to HTML and to other display and interaction technologies such as those on mobile devices. The more you tie yourself to HTML the harder that transition will be.
(2005-04-14 09:03:18.0) Permalink Comments [8]
Posted by Keshtidar on April 21, 2005 at 02:26 PM PDT #
Posted by David on July 25, 2006 at 04:21 PM PDT #
Posted by Tor Norbye on July 25, 2006 at 04:28 PM PDT #
Posted by David on July 25, 2006 at 04:51 PM PDT #
Posted by Tor Norbye on July 25, 2006 at 05:12 PM PDT #
Posted by David on July 25, 2006 at 08:42 PM PDT #
Posted by Tor Norbye on July 25, 2006 at 09:39 PM PDT #
Posted by David on July 25, 2006 at 09:56 PM PDT #