Introduction
In a previous article, we explained how to implement HTML 5 tags for Struts v.1 framework. We won't explain in this article the new attributes that came with HTML 5. For this, please refer to the Struts article, linked above. As Stripes is another framework I use on side projects, let's see now how to implement the same features, extending existing Stripes existing tags!Stripes tag implementation
As we investigated about the best implementation for the new tags in Stripes source code, I noticed all tags extend an abstract HtmlTagSupport class. This class contains an attributes field, which simply is a Map containing attributes names and values of the current tag :
The idea for the implementation will be quite simple : our new classes will "only" have to add new attributes to this existing Map!
To keep example simple, we will only extend one tag (text), and add three attributes for each (required, pattern, and placeholder). What we do here is just add getters and setters for the attributes, and in these, we set/get the values from the attributes Map :
Once done, we must declare the new classes to a .tld file. As our class extends existing tag, the tag declaration will be copied from existing Stripes tld file, with our new attributes listed at the end of the file :
See the result in action :
No comments:
Post a Comment