How to create program code programmatically

We have a system built on seams / rich surfaces. There is this web page where tables are rendered from a dynamic context (from several different data sources, and each of them uses a different layout to represent essentially the same concept of the real world). As a result, this table is bound to a bean, and its columns / layout are generated from this bean.

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

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

on the JSF page.

The table is bound 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 to do this programmatically?

Thanks!

+2
source share
1 answer
 HtmlAjaxCommandLink commandLink = new HtmlAjaxCommandLink(); commandLink.addActionListener(new SetPropertyActionListener(target, value)); column.getChildren().add(commandLink); 

where target and value are ValueExpression . They can be created using:

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

And the required ELContext can be obtained through FacesContext.getCurrentContext().getELContext()

+6
source

Source: https://habr.com/ru/post/1304332/


All Articles