jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pierre Delisle <Pierre.Deli...@Sun.COM>
Subject Re: Format ParamTag, scriptlets, and the uneasy combination thereof
Date Sat, 12 Apr 2003 23:45:53 GMT
JSTL has twin tag libraries: the EL taglibs (the one you are using which support
EL expression values) and the RT taglibs, which support request-time expression values.

So you can do:

     <fmt_rt:message key="STRING_WITH_DATE">
          <fmt_rt:param value="<%=d%>"/>
     </fmt_rt:message> 

You could also do the following:

     <jsp:useBean id="d" class="java.util.Date"/>
     <fmt:message key="STRING_WITH_DATE">
          <fmt:param value="${d}"/>
     </fmt:message> 

    -- Pierre   

Erik & Aureen Currin wrote:
> I have been leading a localization effort at my company, and have been using
> JSTL to do must of the work..  Unfortunately, the world is not ideal, and
> the JSPs we have rely heavily on scriptlets.  The problem comes when there
> is a parameter defined in a scriptlet that needs to get into a message:
> 
>     <%
>             Date d = new Date();
>     %>
> 
>     <fmt:message key="STRING_WITH_DATE">
>          <fmt:param value="<%=d%>"/>
>     </fmt:message>
> 
> The above represents what I would like to do.  But, the JSTL ParamTag only
> has one setValue method, mainly setValue(String), that expects a EL string.
> Running the above will cause a JSP compile error (not
> setValue(java.util.Date) method).
> 
>  I created a subclass of this class that allows more types to be used:
> 
>     public class FormatTag extends
> org.apache.standard.taglibs.tag.el.fmt.ParamTag {
>           public void setValue(Date d) {  value = d;   }
>           public void setValue(Integer i) { value = i; }
>           public void setValue(int i) { value = new Integer(i); }
>           ...
>     }
> 
> This allows me to use the syntax above.  The value it sets is used by the
> doEndTag, and essentially short-circuits the evaluate of the value as an EL
> string.  I am comfortable using my subclass going forward, but it would be
> nice to have something like the above put into the standard.  Obviously, you
> could use a different setObjectValue() or something if you insist on keeping
> setValue() type-safe.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org


Mime
View raw message