John
John

Reputation: 660

How to create commandlink programmatically

We have a system built on seam/richfaces. There's this webpage where the tables are rendered from dynamic context (from multiple different datasources, and each of them uses a different layout to represent essentially the same real world concept). As a result, this table is binded to a bean, and it's columns/layout are generated from this bean.

Now I need to add a command link on a specific column, equivalent to

<a4j:commandLink value="#{actBean.Ids}" action="#{actBean.genDetails}">
    <f:setPropertyActionListener target="#{actBean.Ref}" value="#{cont}"/>
</a4j:commandLink>

in a JSF page.

The table is binded to a managed bean with

HtmlDataTable dataTable = new HtmlDataTable();
HtmlColumn column = new Column();
//some code to setup column name, value etcs
dataTable.getChildren().add(column);
//What do I do here to bind a commandlink with a property action 
//listener to column?

My question is, how do I do this programmatically?

Thanks!

Upvotes: 3

Views: 4532

Answers (1)

Bozho
Bozho

Reputation: 597116

HtmlAjaxCommandLink commandLink = new HtmlAjaxCommandLink();
commandLink.addActionListener(new SetPropertyActionListener(target, value));
column.getChildren().add(commandLink);

where target and value are ValueExpression's. These can be created with:

ExpressionFactory.getInstance().createValueExpression(ctx, expression, expectedType)

And the required ELContext can be obained via FacesContext.getCurrentContext().getELContext()

Upvotes: 8

Related Questions