3

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!

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
John
  • 628
  • 9
  • 26
  • @John @BalusC or @Bozho will show you how to. You have to bind your JSF component in your Managed bean in order to get your goal. – Arthur Ronald Mar 17 '10 at 03:57
  • @Arthur I actually did the whole thing based on BalusC's tutorial. It's just that I couldn't find a proper way to bind the commandlink and propertyActionListener objects (on HtmlColumn objects), they are no where to be found in the richfaces/jsf api (or am I just missing them). – John Mar 17 '10 at 04:01
  • Be cool. @Bozho is online. He will show you how to – Arthur Ronald Mar 17 '10 at 04:03
  • It's the in middle of the night here, so I couldn't quite grasp the question, being a bit sleepy. Will take a look in the morning. Before that, please provide some other code, which you are currently only describing – Bozho Mar 17 '10 at 04:12
  • thx, I added more codes. The whole thing is probably too much detail. I hope the section I added gives enough idea to what I'm having trouble with. – John Mar 17 '10 at 04:17

1 Answers1

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

Christian
  • 21
  • 1
  • 3
  • 7
Bozho
  • 554,002
  • 136
  • 1,025
  • 1,121