aspose file tools*
The moose likes JSF and the fly likes Extending JSF Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Extending JSF Components" Watch "Extending JSF Components" New topic
Author

Extending JSF Components

Chris Lynx
Greenhorn

Joined: Jul 26, 2007
Posts: 4
I have just started looking at JSF/JSP etc and am not sure if I am going down the right track with regards to extending the core JSF components.

This is what I have done:

1) I have extended javax.faces.component.html.HtmlCommandButton
2) I have extended com.sun.faces.taglib.html_basic.CommandButtonTag
3) I have registered my extended HtmlCommandButton in faces-config.xml
4) I have created a .tld file which has a tag pointing to my extended CommandButtonTag.

The problem I have is that when i import my taglib into a jsp I dont get any attributes?

Eg if I add an attribute "myAttribute" to my taglib I can reference it from my jsp. However, as my taglib points to my implementation of com.sun.faces.taglib.html_basic.CommandButtonTag I was expecting to be able to get all the attributes associated with it in my jsp.

Therefore I was expecting to be able to do something like:

<myTagLib:myCommandButton value="Test"></myTagLib:myCommandButton>

However, I can not see the value attribute.

Any ideas? Have I gone about JSF component extension in the wrong way?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16232
    
  21

Did you define the "value" property in your TLD?


Customer surveys are for companies who didn't pay proper attention to begin with.
Chris Lynx
Greenhorn

Joined: Jul 26, 2007
Posts: 4
When I put value in my .tld file I see the "value" attribute in the JSP.

My question was more should I need to add value to the .tld file as the tag in my tld file points to my tag class which is an extension of com.sun.faces.taglib.html_basic.CommandButtonTag which has "value" already?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16232
    
  21

TLD's don't inherit. If you're subclassing an existing custom tag, your new tag's TLD must define all properties you want that tag to support, not just ones that are unique to the subclass.
Chris Lynx
Greenhorn

Joined: Jul 26, 2007
Posts: 4
Thanks for confirming this.

So basically if I extend HTMLCommandButton/Tag and want to use all of its attributes as well as a new one defined in my implementation, I would have to redefine all the ones I wanted to use! Sounds like a bit of a nightmare...
Yogesh Gnanapraksam
Ranch Hand

Joined: Dec 17, 2009
Posts: 133
If all the attributes have to be redefined then what is the purpose of extending an existing JSF component to create a custom JSF component.
I have started working on creating custom jsf components,I am extending UIInput text and it is a really a surprise for me to find that
all the attributes have to be redefined on custom component.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extending JSF Components