• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simon - Are Tag Attributes Required to be Write-only?  RSS feed

 
Pete Cassetta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have encountered a strange behavior in Tomcat 4.04 recently. If I write a simple tag which extends TagSupport, and one of my attributes is read/write, then Jasper bombs during compilation of any page which uses this tag attribute with a "Unable to find setter method for attribute" exception.
My reason for making some attributes read/write is that I want cooperating tags (nested inside the outer tag) to read their values. For example:
<ui:columns defaultWidth="20">
<ui:column width="25">Custom width</ui:column>
<ui:column>Default width</ui:column>
</ui:columns>
So the "columns" tag needs both a setter and a getter for the attribute "defaultWidth".
Anyway, if the "columns" tag includes a getter like:
public int getDefaultWidth() { return width; }
Then I'll get the compile error. If I make the getter non-public like so, then it's fine:
int getDefaultWidth() { return width; }
All this to ask a simple question: does the tag library standard state that attributes must be write-only?
Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The return values of your getters, like the single parameter of your setters, must be a String.
hth,
bear
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or more specifically, the return types of your getters needs to match up with the parameter type of your setters. They don't have to just be strings.
Well, this is the rule in JDK 1.4 anyway - you can get away with breaking it under 1.3 and below. Basically, the rules around the JavaBeans mechanism have been changed to be more restrictive.
When writing the book, one of the examples didn't follow this rule and worked successfully under JDK 1.3, but not under JDK 1.4 where you get a "setter method cannot be found" error.
HTH
Simon
 
Pete Cassetta
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Simon Brown:
Or more specifically, the return types of your getters needs to match up with the parameter type of your setters. They don't have to just be strings.
Well, this is the rule in JDK 1.4 anyway - you can get away with breaking it under 1.3 and below. Basically, the rules around the JavaBeans mechanism have been changed to be more restrictive.

Guys,
Thanks for the detailed explanation. I had found a workaround, as you know, but it is so much more satisfying (and educational) to know what's really happening.
I probably need to buy your book Simon, as I am writing a lot of custom user-interface tags these days and getting tremendous benefit from them (as well as from some of the open source ones I've started using). Taglibs make my JSPs so much shorter and cleaner. They're great.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!