File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enumeration of values for an attribute for a custom tag?

 
Nathan Russell
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wonder if anyone can help. I am creating a small library of JSP tags, and am struggling with the TLD - in particular specifying a fixed set of possible values for a given attribute.

http://java.sun.com/products/jsp/tutorial/TagLibraries11.html#62167 tells me that the format for the attribute element is:


This is fine, and I have a TLD with this in it:


This works fine, but what I really want the TLD to describe is that the layoutCol1 attribute can have one of the values label or field or helpicon

I've read that that I can do this at runtime by having a class that extends TagExtraInfo and writing the isValid method. But what I'd really like to do is do it in the TLD - that after all should describe my tag and all of its attributes?

Any pointers gratefully received;

Cheers

Nathan


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2167
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan,

There is an option of giving a "type" attribute in the attribute element.
check: SUN tutorial

However I don't know whether you can use an enum there...
Regards,
Frits
 
Nathan Russell
Ranch Hand
Posts: 75
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits, but I dont think the type attribute is what I want (I think it is for when you allow expressions as values for your custom attribute you can say what object type the expression return should be)

There is an interesting line in the page I originally posted - in the section Attribute Validation, the first line reads:
The documentation for a tag library should describe valid values for tag attributes. When a JSP page is translated, a JSP container will enforce any constraints contained in the TLD element for each attribute.

Does anyone know what documentation they refer to? The way I am reading this is that there are some documentation tags which I should include in my TLD which (amongst other things) can describe the valid option values for an attribute?

Cheers

Nathan
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2167
57
Android Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan,

Just an small example that uses an enum as an attribute:
My small implementation consists of the following files:
  • enum definition
  • TLD
  • Servlet
  • JSP
  • TagHandler

  • defining the enum

    the TLD entry only allowing an enum for the attribute layoutCol1:

    The Servlet code:

    The jsp:

    The TagHandler code:

    The queryString contains the parameter "anOption", and I am using the URL that maps to my servlet with the queryString "?anOption=label"
    The output on the page is:
    doStartTag LABELdoEndTag LABEL


    There is no way you can put a String or other object than an LayoutCol enum as an attribute to your Tag.
    Does this answer your question?

    Regards,
    Frits
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic