I was a little brain-dead yesterday... this helped. I have it all working now.
Thanks again,
Bobby Rosenberger
On 11/17/05, Craig McClanahan <[EMAIL PROTECTED]> wrote:
On 11/17/05, Bobby Rosenberger < [EMAIL PROTECTED]> wrote:Hey everyone,
I've floundered enough.
I would like to dynamically create a link that has an associated actionListener. I understand how to do it using the tags... but dynamically, I'm getting stumped... could someone help me over the hump? (my hump, my hump, ... ok shoot me.) I'm creating the link as follows:
UICommand link = new UICommand();
link.setRendererType("javax.faces.Link");
link.setId("myLink");
I've also defined the following method:
public void listen(ActionEvent e){
String id = e.getComponent().getClientId(getContext());
System.out.println("Link Id: " + id);
}
Now the question is.. how the heck to I hood the two together? I would like the "listen" method to be called when anyone clicks on the link...
You might find it easier to use an action method, rather than an ActionListener, instead ... that way, it's easy to drive navigation. The steps involved are fairly simple:
* Change your method signature to return a String and take no arguments
(i.e. just like a statically linked action method)
* Make sure this method is defined in a managed bean
(for purposes of example, we'll assume it is under the
name "foo"
* Add the following logic to establish the linkage, via a
method binding (note that this is almost exactly what
the JSP tag does for <h:commandLink>:
FacesContext fc = FacesContext.getCurrentInstance();
MethodBinding mb = fc.getApplication().createMethodBinding("#{foo.listen}", null);
link.setAction(mb);
Any help would be greatly appreciated.
Bobby
Craig

