Warren Bell wrote:
Would I just use <t:messages layout="text"/> in my jsp where layout="text"
would be implemented in my my.package.extend.MyMsgRenderer class that
extends org.apache.myfaces.renderkit.html.HtmlMessagesRenderer?

Ah, now you're wanting to add extra properties to a component rather than just changing the renderer, and things get *much* more complicated.

First, you need to create a new .tld file with the new attribute defined in it, so that the JSP processor recognises the new attribute as valid. You define your own namespace for this new tag library, eg "warren.com/taglib1" then add references to this taglib in your .jsp files with some unique prefix.

See tomahawk/tld/tomahawk.tld from the MyFaces source for an example tld.

However JSP provides no mechanism to "inherit" attributes, so your new TLD entry needs to contain a copy-and-paste of the entire set of attribute definitions from the parent tag's tld. Ecch. MyFaces work around this by using XML entity definitions, but many servlet engines (incl. tomcat) don't correctly process entity references in .tld files so a preprocessing stage that uses XSLT to expand the entities is needed.

Your tag class needs to have a setter for this new layout property, and update the component with it in its setProperties method.

Having written your tag, you then need to subclass the UIComponent to add your new field. Well, actually you can be sneaky and skip this step, as a component has an attributes map that stores any "properties" that aren't defined via setter/getter methods on the UIComponent. Generally that's bad form I think but probably ok in this case.

Your custom renderer can then use component.getAttribute("layout") to determine what layout was defined via the JSP tag and do the right thing.

About now is when you start thinking about using Facelets instead of JSP. I have only read the basic docs, but avoiding all this JSP tag garbage can't be bad.

Regards,

Simon

Reply via email to