wood burning stoves 2.0*
The moose likes Struts and the fly likes HtmlCommandLink in a custom component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "HtmlCommandLink in a custom component" Watch "HtmlCommandLink in a custom component" New topic
Author

HtmlCommandLink in a custom component

Florian Fogl
Greenhorn

Joined: Nov 04, 2003
Posts: 8
Hi everybody,

seems like I got stuck with this Problem here: I am trying to create HtmlCommandLink within my custom component that points to a method via method binding. My code looks as follows:

ResponseWriter writer = context.getResponseWriter();
HtmlForm htmlForm = new HtmlForm();
htmlForm.encodeBegin(getFacesContext());
HtmlCommandLink htmlCommandLink = new HtmlCommandLink();
htmlCommandLink.setParent(htmlForm);
MethodBinding methodBinding = getFacesContext().getApplication().createMethodBinding("#{TestAction.defaultAction}", null);
htmlCommandLink.setAction(methodBinding);
htmlCommandLink.encodeBegin(getFacesContext());
writer.write("Link");
htmlCommandLink.encodeEnd(getFacesContext());
htmlForm.encodeEnd(getFacesContext());

The Link is created in the page and I can click on it but the method is not invoked. I can invoke it in the code manually which means the reference to the method is working. Am I missing something here?

Any help appreciated

Florian
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Originally posted by Florian Fogl:
Hi everybody,

seems like I got stuck with this Problem here: I am trying to create HtmlCommandLink within my custom component that points to a method via method binding. My code looks as follows:

ResponseWriter writer = context.getResponseWriter();
HtmlForm htmlForm = new HtmlForm();
htmlForm.encodeBegin(getFacesContext());
HtmlCommandLink htmlCommandLink = new HtmlCommandLink();
htmlCommandLink.setParent(htmlForm);
MethodBinding methodBinding = getFacesContext().getApplication().createMethodBinding("#{TestAction.defaultAction}", null);
htmlCommandLink.setAction(methodBinding);
htmlCommandLink.encodeBegin(getFacesContext());
writer.write("Link");
htmlCommandLink.encodeEnd(getFacesContext());
htmlForm.encodeEnd(getFacesContext());

The Link is created in the page and I can click on it but the method is not invoked. I can invoke it in the code manually which means the reference to the method is working. Am I missing something here?

Any help appreciated

Florian


I guess u r missing one line:
htmlCommandLink.setId("put any id here");

For component created programatically, JSF doesn't create the id automatically, you will have to set it up on ur own.


- Varun
Florian Fogl
Greenhorn

Joined: Nov 04, 2003
Posts: 8
Originally posted by K Varun:


I guess u r missing one line:
htmlCommandLink.setId("put any id here");

For component created programatically, JSF doesn't create the id automatically, you will have to set it up on ur own.


Thanks K Varun for your reply! Alas, it didn't do the trick! The ID is created even if I don't set it manually. Any other ideas?
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Can you show me the log? ... README file contains the procedure of turning the logging on.

- Varun
Florian Fogl
Greenhorn

Joined: Nov 04, 2003
Posts: 8
Hi K Varun,

I thin I know what the problem is. I create the compononent within the method "encodeBegin" of my custom component and it gets never registered with the current FacesContext. So, there is no broadcast to the default action listener and therefore the method is not invoked.

I think I am missing something here! How can I tell my custom component to create a link that acts like a command link and invokes a method? That's what I'm trying to do!

Thanks!
Varun Khanna
Ranch Hand

Joined: May 30, 2002
Posts: 1400
Instead of using "writer.write("Link");"
why are you not using the method setValue("Link") on HtmlCommandLink ?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HtmlCommandLink in a custom component
 
Similar Threads
dynamic fields display
Creating HtmlCommandButton and HtmlForm in a custom tag
Dynamically add Children Link Element (a standard jsf commandLink child)
Popup working with CommandButton but not with CommandLink
how to build CommandLink