Wednesday, October 24, 2012

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

As soon as I posted the previous blogpost Java Evangelist John Yeary's Blog: JSF 2.x Tip of the Day: Programmatic <h:commandLink/> I got a request for how to do it with RichFaces. The process is almost the same.

Here is an example for creating <a4j:commandLink/>
1
2
3
4
5
6
7
8
9
10
private UICommandLink createSortingLink(String value) {
       Application application = context.getApplication();
       Class<?>[] clazz = new Class<?>[]{};
       UICommandLink commandLink = (UICommandLink) application.createComponent(UICommandLink.COMPONENT_TYPE);
       commandLink.setValue(value);
       commandLink.setActionExpression(createMethodExpression("#{tableBean.sort()}", String.class, clazz));
       commandLink.setValueExpression("render", createValueExpression("#{tableBean.render}", null));
       commandLink.setRender("tableForm:resultsTable");
       return commandLink;
   }
This example creates one for a table sorter on a RichFaces data table.

0 comments :

Popular Posts