Erik,

Please posting the code , I am also interested.

Thanks
John

Inactive hide details for "Erik Beijnoff" <[EMAIL PROTECTED]>"Erik Beijnoff" <[EMAIL PROTECTED]>




          "Erik Beijnoff" <[EMAIL PROTECTED]>

          08/31/2005 02:59 PM
          Please respond to "Tag Libraries Users List"



To: taglibs-user@jakarta.apache.org
cc:
Subject: Re: JSTL and Java Constants



>I would like to do something like:
>
>a) <c:when test="${item.type == ContentType.URL}">
>
> This won't work. I could hack it around with a scriptlet and an import
>at the top of my JSP, but that seems to me like
>violating the separation between View and Control
>
>
>>You may want to see this -
>
>>http://forums.java.sun.com/thread.jspa?threadID=508847&messageID=2543490
>

One big tradeoff with that approach is that you have to specify your
constants in one Constant class where they may not naturally belong. Another
one would be that you would have to import all external constants into that
class, thereby creating double maintenance work. And a third would be that
you'd need to import the constant class at the top of each page.

My workaround for the fact that you directly can't reach a static variable
in a java class is to make invoke a static method through the EL which in
turns does some reflective parsing to find the constant. It would look like
this:
<c:when test="${item.type == fn:const('URL')}">

You could create several different extractor methods to have different level
of generality in the method so that you can reach constants in a predefined
class, in a package, or with the full class name:

<c:when test="${item.type == fn:const('ActionHandler.URL')}"> or

<c:when test="${item.type == fn:const('java.lang.Integer.MAX_VALUE')}">

With this approach you are guaranteed to not have any hard coded magic
values in your jsp. I do not have the code that does the extraction here at
my work, but if you are interested, I can send it over or post it here.

Regards,
Erik Beijnoff





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




The information contained in this message may be CONFIDENTIAL and is for the intended addressee only. Any unauthorized use, dissemination of the information, or copying of this message is prohibited. If you are not the intended addressee, please notify the sender immediately and delete this message.

Reply via email to