JavaServer Faces - HtmlCommandLink in Dynamic datatable

Hi All,

I got the dynamic data table working with help from http://balusc.xs4all.nl/srv/dev-jep-dat.html

I want to have a command link for all the cells . I tried the following code. It shows the link. But when I click on the link it just refreshes the same page

HtmlCommandLink column1Text = new HtmlCommandLink();

ValueBinding vb =

FacesContext.getCurrentInstance().getApplication().createValueBinding("#{contact.createSetup}");

column1Text.setValueBinding("action", vb);

ValueBinding vbvalue =

FacesContext.getCurrentInstance().getApplication().createValueBinding("#{myItem[" + i + "]}");

column1Text.setValueBinding("value", vbvalue);

UIParameter param = new UIParameter();

param.setName("parm1");

param.setValue("test");

column1Text.getChildren().add(param);

// Set column.

UIColumn column = new UIColumn();

column.setHeader(header);

column.getChildren().add(column1Text);

// Add column.

dynamicTable.getChildren().add(column);

Any idea what I am doing wrong? Any help is appreciated much..

regards

Reghu

[1183 byte] By [rwarriera] at [2007-11-26 23:09:45]
# 1
You need to create methodbinding in a commandlink, not valuebinding.
BalusCa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
You'll want to unsure you assign an ID to the commandLink. You'll need to take steps to ensure the ID is unique (perhaps AtomicInteger).
rlubkea at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
You can use the displaytag / displaytable ( google it ) to make dynamic tables.In others projects I used this component.See ya.
Guilherme_Kellera at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
BulusC,Your code examples got me this far.. thanks a lot.Do you have an example to show how to create a methodbinding ? I am new to jsf.thanks a bunch
rwarriera at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
BalusC,Your solution worked. Thank You so much...regardsReghu
rwarriera at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hello BalusC,

i am not sure if I have understand your tip how to fix it.

I want to build a menu, too.

linktext = new HtmlOutputText();

linktext.setValue("WorkBench");

MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("workbench", null);

HtmlCommandLink cmdlink = new HtmlCommandLink();

cmdlink.setAction(mb);

cmdlink.setImmediate(true);

cmdlink.setId("MainMenuWorkbenchLink");

cmdlink.getChildren().add(linktext);

this.menu.getChildren().add(cmdlink);

But I get an javax.faces.el.ReferenceSyntaxException: workbench when I try to set up the mb.

any idea why?

Greets and Thanks

Reddingoa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
"workbench" is not a methodbinding. Replace it by for example "{#myBean.someMethod}".
BalusCa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Ofc it is not a method slap myself

But is it a valuebinding?

I want to navigate to a page I have set up in the faces-config.xml with a normal link

and onthefly

<navigation-rule>

<display-name>workbench</display-name>

<navigation-case>

<from-outcome>workbench</from-outcome>

<to-view-id>/workbench.jsp</to-view-id>

</navigation-case>

</navigation-rule>

Reddingoa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
Valuebinding is intented to be used in setValue().If you just want to put a String for the navigation case, then just put a String in it instead of a MethodBinding.
BalusCa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
Yes, but looking at the Method setAction of the class UICommand:public void setAction(javax.faces.el.MethodBinding action)so I cannot add a "singel" String.
Reddingoa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
Hmm, I've overlooked that and I don't see other ways to put a String in it anyway. Can't you just put a dummy action method in the backing bean returning the right String?
BalusCa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12
lets get dirty :-DI had the same idea but thought, that there is a "nice" way to do that.
Reddingoa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
I agree that this is dirty, but I don't see other ways quickly.
BalusCa at 2007-7-10 14:05:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...