How to create commandlink programmatically

那年仲夏 提交于 2020-01-21 15:26:24

问题


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!


回答1:


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()



来源:https://stackoverflow.com/questions/2458769/how-to-create-commandlink-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!