Friday, January 11, 2013

JSF 2.x Tip of the Day: Programmatically Creating a <h:outputText/>

In this tip of the day we create one of the most basic components in our JSF arsenal: <h:outputText>.
This example uses another library called jsf-utils to handle the heavy lifting.
1
2
3
4
5
public HtmlOutputText createHtmlOutputText(final FacesContext context, final String valueValueExpression, Class<?> valueType) {
    HtmlOutputText text = (HtmlOutputText) context.getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
    text.setValueExpression("value", JSFUtils.createValueExpression(valueValueExpression, valueType));
    return text;
}

0 comments :

Popular Posts