Friday, January 11, 2013

JSF 2.x Tip of the Day: RichFaces Programmatically Creating an <a4j:commandLink/>

This example of how to create an <a4j:commandLink/> uses another library called jsf-utils to handle the heavy lifting.

The method below will create the <a4j:commandLink/> component, any additional configuration will need to be performed programmatically, or using the tag attributes.

1
2
3
4
5
6
7
8
public UICommandLink createUICommandLink(final FacesContext context, final String value, final String render, final String methodExpression) {
    Class<?>[] clazz = new Class<?>[]{};
    UICommandLink link = (UICommandLink) context.getApplication().createComponent(UICommandLink.COMPONENT_TYPE);
    link.setValue(value);
    link.setRender(render);
    link.setActionExpression(JSFUtils.createMethodExpression(methodExpression, String.class, clazz));
    return link;
}
You would bind it to a backing bean to a UICommandLink component;
1
<a4j:commandLink binding="#{indexBean.commandLink1}"/>

0 comments :

Popular Posts