如何以编程方式创建commandlink

Joh*_*ohn 2 jsf seam richfaces

我们有一个建立在seam/richfaces上的系统.这个网页是从动态上下文(来自多个不同的数据源,每个都使用不同的布局来表示基本相同的真实世界概念)呈现的.结果,这个表被绑定到一个bean,它的列/布局是从这个bean生成的.

现在我需要在特定列上添加命令链接,相当于

<a4j:commandLink value="#{actBean.Ids}" action="#{actBean.genDetails}">
    <f:setPropertyActionListener target="#{actBean.Ref}" value="#{cont}"/>
</a4j:commandLink>
Run Code Online (Sandbox Code Playgroud)

在JSF页面中.

该表绑定到托管bean

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?
Run Code Online (Sandbox Code Playgroud)

我的问题是,我该如何以编程方式执行此操作?

谢谢!

Boz*_*zho 7

HtmlAjaxCommandLink commandLink = new HtmlAjaxCommandLink();
commandLink.addActionListener(new SetPropertyActionListener(target, value));
column.getChildren().add(commandLink);
Run Code Online (Sandbox Code Playgroud)

其中,targetvalueValueExpression的.这些可以创建:

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

并且ELContext可以通过获得所需的FacesContext.getCurrentContext().getELContext()