my dog learned polymorphism*
The moose likes JSF and the fly likes Passing attributes to 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 » Java » JSF
Bookmark "Passing attributes to custom component" Watch "Passing attributes to custom component" New topic

Passing attributes to custom component

Robe Eleckers

Joined: Jul 08, 2009
Posts: 9

I'm building a custom component by extending the UIComponentBase class and overriding the encodeAll method to generate html output. This component is added to my custom taglib so now I can call the component in my facelet with:

I would like to pass some attributes to this component, like this:

When I do this I get the error message 'The attribute root is not defined in the component's interface'. I know where to define these attributes when creating a composite custom component (<composite:interface>), but where can I define these attributes in my case? Unfortunately my google search did not help me since most custom component tutorials are about composite components.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964

Is this a fatal message, or just a complaint in the log?

In basic JSP tags, you had to define the attributes in a TLD file. In basic JSF - well, I forget, but I think it was slightly different. When using Facelets, the rules changed again, but the error message became only a message instead of a full-blown error.

Customer surveys are for companies who didn't pay proper attention to begin with.
Robe Eleckers

Joined: Jul 08, 2009
Posts: 9
Hi, it was a fatal message. Also generated a stacktrace when running the project. I fixed it now by implementing my own UIComponentELTag, to this implementation I added a property which is now set. My taglib had to be changed for this, now it looks like:

So the good thing is it works, however I feel it's more work now than really necessary. Are there perhaps any annotations which can help with this configuration?
wood burning stoves
subject: Passing attributes to custom component
Similar Threads
Question about page 374 of Head First Design Patterns
JSF complicated custom component
Reusable composite component with children.
Basic Concepts of AWT Event Generation
Generating <script> tag from Custom JSF Tag