Java Reference
In-Depth Information
Tim Says. . .
Stripes Has Two Tag Libraries. Wait, What?
The main Stripes tag library is imported, as Freddy showed
in Chapter 2 , Stripes 101: Getting Started, with the URI
http://stripes.sourceforge.net/stripes.tld . There is a second, and
largely identical, tag library that comes with Stripes that can
be imported with the URI http://stripes.sourceforge.net/stripes-
dynattr.tld . The main difference between these two tag libraries
is that the input tags in the first tag library do not support JSP
dynamic attributes, whereas the ones in the second do.
I advise everyone to use the first library almost all the time.
In fact, for several versions, we had only the first tag library. It
has the advantage of providing much better error checking.
Because the set of attributes that a tag accepts is limited to
a fixed and known set, the JSP compiler can provide compile-
time checking of attribute names, and IDEs can usually spot
errors immediately. This is especially helpful for attributes that
are just passed through to the HTML, because Stripes won't
complain if those attributes are misspelled. For instance, if
you typed <s:text name="username" clas="important"/> , the mis-
spelling of “class” would be flagged immediately, whereas with
dynamic attributes the clas attribute would just get passed
through to the HTML. You wouldn't be told about the typo in
the IDE, and you'd notice the problem later only when the text
field wouldn't be displayed with the "important" class.
Despite these advantages, there are times when you need
HTML tags to have attributes that aren't technically valid HTML.
This is quite common with Ajax or JavaScript libraries. For exam-
ple, you might want to write <s:text name="friend" autocom-
plete="off"/> . Since “autocomplete” isn't valid HTML, the stan-
dard Stripes tag won't let you write it. For this you have to
use the tag that supports dynamic attributes—this will pass any
unknown attributes through to the HTML.
It's perfectly valid to import both tag libraries on the same page
(with different prefixes) and intermingle them within the same
form. That's why my advice is to use the standard library where
possible—to get the best error checking possible—and then use
the dynamic tag library just on the tags where it is needed.
 
Search WWH ::




Custom Search