JSF 2 OutputText Example

JavaServer Faces (JSF 2) provides a number of user interfaces components that cover the most common requirements, one of the most important component is a <h:outputText/> component. The outputText is a component that has a value, optionally retrieved from a model tier bean via expression, that is displayed to the user. The user cannot directly modify the rendered value; it is for display purpose only. If you are looking for the configuration of complete application, please read our JSF 2 Setup Tutorial.

1. Managed Bean

The following lines of code should provide you the proper ManagedBean for containing the greeting message, that is the message shall be displayed several times using the outputText component. That’s not the all things that you would see in this example; also, the outputText can be used for displaying a text containing a HTML tags.

Once you would be displaying a messages containing HTML Tags, you should use the property escape that provided by the <h:outputText/>.

The escape property can take two values; true or false, the true value indicates that the HTML tags inside the component should be discarded, while the false is an indication of being the HTML Tags are considered.

The outputText component is able to accept values from the managed beans; by using the value property that could have an expression connected to a value in a certain managed bean or by type an inline message within it.