problem with fmt:formatDate

2004-10-14 Thread Flavio Tordini
Hi all,
I'm using the fmt:formatDate tag and I discovered a strange behaviour:

When a JSP is requested without specifying the Accept-Language HTTP header 
and no locale has been explicitly set in the JSP, the date is not formatted 
and the result of Date.toString() is returned instead.

I checked the JSTL spec, this is what it says to do when the algorithm cannot 
find a Locale:
If no match is found after the above two steps, it is up to the formatting 
action to take a corrective action.
I don't know what corrective action means in this context, but I think that 
using the default JVM locale would be much better than toString().

here's a sample JSP, you can test it with curl or wget:

%@ taglib prefix=fmt uri=http://java.sun.com/jsp/jstl/fmt; %
jsp:useBean id=now class=java.util.Date /
fmt:formatDate value=${now} pattern=/

regards,
flavio tordini


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



Re: problem with fmt:formatDate

2004-10-14 Thread Kris Schneider
I'm not arguing whether or not it's the *best* thing to do, but the JSTL 1.1
Spec. includes:

9.9 fmt:formatDate
..
Null  Error Handling
- If value is null or empty, nothing is written to the current JspWriter object
and the scoped variable is removed if it is specified (see attributes var and
scope).
- If timeZone is null or empty, it is handled as if it was missing.
- If this action fails to determine a formatting locale, it uses
java.util.Date.toString() as the output format.

So, it looks like it's at least behaving according to the spec...

Quoting Flavio Tordini [EMAIL PROTECTED]:

 Hi all,
 I'm using the fmt:formatDate tag and I discovered a strange behaviour:
 
 When a JSP is requested without specifying the Accept-Language HTTP header
 
 and no locale has been explicitly set in the JSP, the date is not formatted 
 and the result of Date.toString() is returned instead.
 
 I checked the JSTL spec, this is what it says to do when the algorithm cannot
 
 find a Locale:
 If no match is found after the above two steps, it is up to the formatting 
 action to take a corrective action.
 I don't know what corrective action means in this context, but I think that
 
 using the default JVM locale would be much better than toString().
 
 here's a sample JSP, you can test it with curl or wget:
 
 %@ taglib prefix=fmt uri=http://java.sun.com/jsp/jstl/fmt; %
 jsp:useBean id=now class=java.util.Date /
 fmt:formatDate value=${now} pattern=/
 
 regards,
 flavio tordini

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

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



RE: easy enough to write, but curious if it'll exist as part of JSTL (forEach question)

2004-10-14 Thread Johnson, Chris
Wouldn't this be nice?

c:join items='${employees}' delim=','/

-Original Message-
From: Rick Reumann [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 13, 2004 11:09 PM
To: Tag Libraries Users List
Subject: Re: easy enough to write, but curious if it'll exist as part of
JSTL (forEach question)


Martin Cooper wrote the following on 10/13/2004 11:31 PM:
 I'm not sure what you mean by prepending or appending. What do you 
 want to prepend or append to (and why)?

Maybe I'm alone but it seems like I'm often having to display what I'm 
iterating over with forEach and usually I need something displayed 
'between' each iteration, such as a comma after each name if iterating 
over names.

Actually come to think of it, I'm being an idiot:) I'm so used to my Tag

where I pass in a collection and it basically does what you are doing 
below.

I guess I was thinking of giving forEach too much power with something 
like...

c:forEach items='${collection}' property='someProperty'
append=', ' ignoreLast='true'/

Which might be..

c:forEach items='${employees}' property='lastName' append=', ' 
ignoreLast='true'/

Which would spit out a comma separated list of lastNames from the 
collection of Employee beans in employees.

Then again this is probably dumb to delegate that much to a forEach tag.

sorry been a long week and it aint over:)


 As for the ignore part, that's already there. If you use the 
 'varStatus' attribute of c:forEach, you can then test 'status.first'

 and 'status.last'. For example:
 
 c:forEach var=item items=${items} varStatus=status
   c:set var=csv value=${csv}${item}/
   c:if test=${!status.last}
 c:set var=csv value=${csv},/
   /c:if
 /c:forEach






-- 
Rick

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


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



RE: easy enough to write, but curious if it'll exist as part of JSTL (forEach question)

2004-10-14 Thread Kris Schneider
%@ page contentType=text/plain %
%@ taglib prefix=fn uri=http://java.sun.com/jsp/jstl/functions; %
% pageContext.setAttribute(strArray, new String[] { zero, one, two,
three }); %
${fn:join(strArray, ,)}

Which produces:

zero,one,two,three

Quoting Johnson, Chris [EMAIL PROTECTED]:

 Wouldn't this be nice?
 
 c:join items='${employees}' delim=','/
 
 -Original Message-
 From: Rick Reumann [mailto:[EMAIL PROTECTED] 
 Sent: Wednesday, October 13, 2004 11:09 PM
 To: Tag Libraries Users List
 Subject: Re: easy enough to write, but curious if it'll exist as part of
 JSTL (forEach question)
 
 
 Martin Cooper wrote the following on 10/13/2004 11:31 PM:
  I'm not sure what you mean by prepending or appending. What do you 
  want to prepend or append to (and why)?
 
 Maybe I'm alone but it seems like I'm often having to display what I'm 
 iterating over with forEach and usually I need something displayed 
 'between' each iteration, such as a comma after each name if iterating 
 over names.
 
 Actually come to think of it, I'm being an idiot:) I'm so used to my Tag
 
 where I pass in a collection and it basically does what you are doing 
 below.
 
 I guess I was thinking of giving forEach too much power with something 
 like...
 
 c:forEach items='${collection}' property='someProperty'
 append=', ' ignoreLast='true'/
 
 Which might be..
 
 c:forEach items='${employees}' property='lastName' append=', ' 
 ignoreLast='true'/
 
 Which would spit out a comma separated list of lastNames from the 
 collection of Employee beans in employees.
 
 Then again this is probably dumb to delegate that much to a forEach tag.
 
 sorry been a long week and it aint over:)
 
 
  As for the ignore part, that's already there. If you use the 
  'varStatus' attribute of c:forEach, you can then test 'status.first'
 
  and 'status.last'. For example:
  
  c:forEach var=item items=${items} varStatus=status
c:set var=csv value=${csv}${item}/
c:if test=${!status.last}
  c:set var=csv value=${csv},/
/c:if
  /c:forEach
 
 
 
 
 
 
 -- 
 Rick

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

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



RE: easy enough to write, but curious if it'll exist as part of JSTL (forEach question)

2004-10-14 Thread Johnson, Chris
There you go!

I figured there was probably alredy something out there, I just didn't
have the need to look.

-Original Message-
From: Kris Schneider [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 14, 2004 7:12 AM
To: Tag Libraries Users List
Subject: RE: easy enough to write, but curious if it'll exist as part of
JSTL (forEach question)


%@ page contentType=text/plain %
%@ taglib prefix=fn uri=http://java.sun.com/jsp/jstl/functions; %
% pageContext.setAttribute(strArray, new String[] { zero, one,
two, three }); % ${fn:join(strArray, ,)}

Which produces:

zero,one,two,three

Quoting Johnson, Chris [EMAIL PROTECTED]:

 Wouldn't this be nice?
 
 c:join items='${employees}' delim=','/
 
 -Original Message-
 From: Rick Reumann [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, October 13, 2004 11:09 PM
 To: Tag Libraries Users List
 Subject: Re: easy enough to write, but curious if it'll exist as part
of
 JSTL (forEach question)
 
 
 Martin Cooper wrote the following on 10/13/2004 11:31 PM:
  I'm not sure what you mean by prepending or appending. What do you
  want to prepend or append to (and why)?
 
 Maybe I'm alone but it seems like I'm often having to display what I'm
 iterating over with forEach and usually I need something displayed 
 'between' each iteration, such as a comma after each name if iterating

 over names.
 
 Actually come to think of it, I'm being an idiot:) I'm so used to my 
 Tag
 
 where I pass in a collection and it basically does what you are doing
 below.
 
 I guess I was thinking of giving forEach too much power with something
 like...
 
 c:forEach items='${collection}' property='someProperty'
 append=', ' ignoreLast='true'/
 
 Which might be..
 
 c:forEach items='${employees}' property='lastName' append=', '
 ignoreLast='true'/
 
 Which would spit out a comma separated list of lastNames from the
 collection of Employee beans in employees.
 
 Then again this is probably dumb to delegate that much to a forEach 
 tag.
 
 sorry been a long week and it aint over:)
 
 
  As for the ignore part, that's already there. If you use the
  'varStatus' attribute of c:forEach, you can then test
'status.first'
 
  and 'status.last'. For example:
  
  c:forEach var=item items=${items} varStatus=status
c:set var=csv value=${csv}${item}/
c:if test=${!status.last}
  c:set var=csv value=${csv},/
/c:if
  /c:forEach
 
 
 
 
 
 
 --
 Rick

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

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


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



Re: problem with fmt:formatDate

2004-10-14 Thread Flavio Tordini
hi Kris,
thank you for your answer! I'm sorry I didn't find that statement before 
posting. Ok,  it's 100% spec compliant... let's hope the spec will be changed 
in the future. It would also be backwards-compatible since noone relies on 
the *absence* of a HTTP request header to determine the date format anyway.

IMHO the problem is someone (like me :) could write:

%@ taglib prefix=c uri=http://java.sun.com/jsp/jstl/core; %
%@ taglib prefix=fmt uri=http://java.sun.com/jsp/jstl/fmt; %
jsp:useBean id=now class=java.util.Date /
fmt:formatDate var=currentYear value=${now} pattern=/
c:forEach begin=1976 end=${currentYear} varStatus=status
  ${status.index}
/c:forEach

and see this:

javax.servlet.jsp.el.ELException: An exception occured trying to convert 
String Thu Oct 14 14:59:29 CEST 2004 to type java.lang.Integer

flavio

On Thursday 14 October 2004 13:33, Kris Schneider wrote:
 I'm not arguing whether or not it's the *best* thing to do, but the JSTL
 1.1 Spec. includes:

 9.9 fmt:formatDate
 ..
 Null  Error Handling
 - If value is null or empty, nothing is written to the current JspWriter
 object and the scoped variable is removed if it is specified (see
 attributes var and scope).
 - If timeZone is null or empty, it is handled as if it was missing.
 - If this action fails to determine a formatting locale, it uses
 java.util.Date.toString() as the output format.

 So, it looks like it's at least behaving according to the spec...

 Quoting Flavio Tordini [EMAIL PROTECTED]:
  Hi all,
  I'm using the fmt:formatDate tag and I discovered a strange behaviour:
 
  When a JSP is requested without specifying the Accept-Language HTTP
  header
 
  and no locale has been explicitly set in the JSP, the date is not
  formatted and the result of Date.toString() is returned instead.
 
  I checked the JSTL spec, this is what it says to do when the algorithm
  cannot
 
  find a Locale:
  If no match is found after the above two steps, it is up to the
  formatting action to take a corrective action.
  I don't know what corrective action means in this context, but I think
  that
 
  using the default JVM locale would be much better than toString().
 
  here's a sample JSP, you can test it with curl or wget:
 
  %@ taglib prefix=fmt uri=http://java.sun.com/jsp/jstl/fmt; %
  jsp:useBean id=now class=java.util.Date /
  fmt:formatDate value=${now} pattern=/
 
  regards,
  flavio tordini

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



Re: easy enough to write, but curious if it'll exist as part of JSTL (forEach question)

2004-10-14 Thread Rick Reumann
Kris Schneider wrote the following on 10/14/2004 8:12 AM:
%@ page contentType=text/plain %
%@ taglib prefix=fn uri=http://java.sun.com/jsp/jstl/functions; %
% pageContext.setAttribute(strArray, new String[] { zero, one, two,
three }); %
${fn:join(strArray, ,)}
very cool, thanks. Wasn't even aware of those functions. It would be 
cool if that fucntion could take a Collection and a bean property. This 
is a nice function though.

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


Re: easy enough to write, but curious if it'll exist as part of JSTL (forEach question)

2004-10-14 Thread Kris Schneider
You may also want to check out section JSP.2.6 Functions of the JSP 2.0 spec
for info on creating your own EL functions.

Quoting Rick Reumann [EMAIL PROTECTED]:

 Kris Schneider wrote the following on 10/14/2004 8:12 AM:
  %@ page contentType=text/plain %
  %@ taglib prefix=fn uri=http://java.sun.com/jsp/jstl/functions; %
  % pageContext.setAttribute(strArray, new String[] { zero, one,
 two,
  three }); %
  ${fn:join(strArray, ,)}
 
 very cool, thanks. Wasn't even aware of those functions. It would be 
 cool if that fucntion could take a Collection and a bean property. This 
 is a nice function though.
 
 -- 
 Rick

-- 
Kris Schneider mailto:[EMAIL PROTECTED]
D.O.Tech   http://www.dotech.com/

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



Re: problem with fmt:formatDate

2004-10-14 Thread Felipe Leme
Flavio,

You're free to add suggest such improvements for the next JSTL specs at:

https://jstl-spec-public.dev.java.net/

-- Felipe
 

On Thu, 2004-10-14 at 10:04, Flavio Tordini wrote:
 posting. Ok,  it's 100% spec compliant... let's hope the spec will be changed 
 in the future. It would also be backwards-compatible since noone relies on 



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