• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The return values of your getters, like the single parameter of your setters, must be a String.
hth,
bear
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic