Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HtmlCommandLink in a custom component

 
Florian Fogl
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Florian Fogl
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show me the log? ... README file contains the procedure of turning the logging on.

- Varun
 
Florian Fogl
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of using "writer.write("Link");"
why are you not using the method setValue("Link") on HtmlCommandLink ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic