This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes default value for a custom tag attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "default value for a custom tag attribute" Watch "default value for a custom tag attribute" New topic
Author

default value for a custom tag attribute

Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
For a custom tag attribute, how do we specify a default value? Is it in the TLD file?
Thx in advance
Tieyi Guo
Greenhorn

Joined: Oct 29, 2001
Posts: 15
As definition in the JSP DTD file:
<!ELEMENT attribute (name, required? rtexprvalue? type?, description?) >
There is no place in the TLD file for you to define the default value for an attribute. However you can specify the "required" field of an attribute as "false", which marks it as optional. Then in your tabclass, define the default value for that attribute. If later when using the tag in your JSP, you specified an attribute value, the JSP container will overwrite the default value by calling the setter method in your tagclass.
Does that make sense?
Tieyi
Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
Yes. Thanks
Shreyas Reddy
Ranch Hand

Joined: Oct 09, 2003
Posts: 49
Hey by the way where did you get this from?
<!ELEMENT attribute (name, required? rtexprvalue? type?, description?) >

I was looking at the JSP 1.1 specs. I didn't find the type and description elements for an attribute element in the dtd.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: default value for a custom tag attribute
 
Similar Threads
Nested quotes in tag
What is the default value of required while defining the tag attribute.
Error in executing <html:text property="firstName" value="<bean:message key="user.firstName" />"/>
taglib custom tags
jstl help