Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it suggested to use h:outputText for everything?

Tags:

I'm new to JSF (just started learning about it 4 days ago) and I'm a bit confused about the usage of h:outputText. I know that is a simple tag, but in most examples I've seen, it's used to output very simple (no need to escape), non-i18n text. For example (taken from here)

<h:outputText value="Transport" /> 

which could be replaced by

Transport  

So, I'm wondering if I'm missing something or if most of the examples I've seen are overcomplicated to the point of insanity.

like image 804
Augusto Avatar asked Apr 04 '11 14:04

Augusto


People also ask

What is H outputText?

The h:outputText tag renders an HTML text.

What is h outputText tag in JSF?

JSF <h:outputText> TagIt is used to render a plain text. If the "styleClass", "style", "dir" or "lang" attributes are present, render a "span" element. If the "styleClass" attribute is present, render its value as the value of the "class" attribute.


1 Answers

If you're using JSF 2.x with Facelets 2.x instead of JSP, then both are equally valid. Even more, Facelets implicitly wraps inline content in a component as represented by <h:outputText> (in other words, it will be escaped!).

Only whenever you'd like to disable escaping using escape="false", or would like to assign id, style, onclick, etc programmatically, or would like to use a converter (either explicit via converter or implicit via forClass), then you need <h:outputText>.

I myself don't use <h:outputText> whenever it is not necessary. Without it, the source code becomes better readable. You can just inline EL in template text like so #{bean.text} instead of doing <h:outputText value="#{bean.text}">. Before JSF 2.0, in JSP and Facelets 1.x, this was not possible and thus the <h:outputText> is mandatory. If your IDE gives warnings on this, it's most likely JSF 1.x configured/minded.

like image 64
BalusC Avatar answered Oct 19 '22 10:10

BalusC