• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to ActionListener manually in custom renderer?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a custom component renderer. And I want to add command link with action listener. I wrote in MyCustomRenderer.encodeBegin such code:


Command link being encoded correctly but my action listener being not invoked.
May be actionListener being not invoked because my Command Link is not a part of Dom Model? If there any chance to add action listener from custom renderer?
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it's because your action listener is not part of the DOM model.

I'm not sure I can really recommend internalizing an action listener to begin with - it deprives the user of the ability, but the actionlistener property isn't supposed to be set to a method, it's supposed to be the name of a method in a backing bean. The JSF framework then resolves the bean reference and invokes that method when the action fires.
 
Bronto Brontkevich
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks alot for your reply!

Tim Holloway wrote:I can really recommend internalizing an action listener



Please! Can you write several lines of code to demonstrate what you mean?
Do you mean that I should insert commandLink to jsp template?:

May be this will solve my problem. But this commandLink is the permanent, obligatory part of my custom component. And I will be bound to repeat the same child tag of my custom element tag. A bit annoying and not eye-filling I think...
Or you meant something else?
 
Bronto Brontkevich
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've just tested this solution. Yes it works. But I would like to know is there some other way to insert in my Renderer links with actionListeners without making them child of my custom tag?
Actually the result markup should contain several actionListeners. And for each actionListener I must insert corresponding <h:commandLink> link child?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do recommend that the selection of actionListener(s) be left to the tag user, yes. If you have some sort of internal action, I suspect that there's a more suitable way of handling it, although without knowing all the details, that's mostly speculation.

When you need multiple actionListeners for a control, use the "f:actionListener" sub-element for each listener. You probably won't get good results using the "h:commandLink" as a sub-element. Also, from a purely superficial point of view, following your example would have users believing that your custom tag is a container, and that the commandLink is a child of the container, having its own actionListener, as opposed to promoting the actionListener up to your custom control.
 
Bronto Brontkevich
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!
I did not know anything about f:actionListener and f:valueChangeListener tags! I'm in samadhi now:)...
But I can not substitute child h:commandLink tags from my custom element to f:actionListener because I can not create new HtmlCommandLink inside of my renderer class. Because when I call encodeParentAndChildren(fContext, link); I get error: "CommandLink must be contained in a form". I have a form on my page. This form is ancestor of my custom tag.
But knowing about f:valueChangeListener will help me very soon. Because I need several valueChangeListeners too!
Thanks again!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic