Why fmt:formatNumber switches response characher encoding?

2002-12-18 Thread Andrew Guts
Hi all,

Why fmt:formatNumber switches response characher encoding? And how to 
avoid it?
My platform is TomCat 4.1.12 on w2k.

Thanks ahead

Andrew


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



RE: Why fmt:formatNumber switches response characher encoding?

2002-12-18 Thread Kan Ogawa
Hi, Andrew.

 -Original Message-
 From: Andrew Guts [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, December 18, 2002 6:36 PM
 
 Why fmt:formatNumber switches response characher encoding? And how to 
 avoid it?
 My platform is TomCat 4.1.12 on w2k.
 
As i18n-capable formatting tags in JSTL are requested, 
These tags initially call the javax.servlet.ServletResponse#setLocale() method.
javax.servlet.ServletResponse#setLocale() sets not only the specified locale,
but also the resonse character encoding suitable for it.
The character encoding setting is dependent on the servlet container.

If the container is Tomcat 4, you can modify the following resource,
org.apache.catalina.util.CharsetMapperDefault.properties in Catalina APIs.

Regards,


Kan Ogawa
[EMAIL PROTECTED]


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




Re: Why fmt:formatNumber switches response characher encoding?

2002-12-18 Thread Andrew Guts
Kan,

Thanks for your answer. I am a newbie with Tomcat/Java and do not know 
how to do that. By the way it switches to the same locale, but different 
character encoding (my language has at least 4 character encodings).

Andrew

Kan Ogawa wrote:

Hi, Andrew.

 

-Original Message-
From: Andrew Guts [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 18, 2002 6:36 PM

Why fmt:formatNumber switches response characher encoding? And how to 
avoid it?
My platform is TomCat 4.1.12 on w2k.

   

As i18n-capable formatting tags in JSTL are requested, 
These tags initially call the javax.servlet.ServletResponse#setLocale() method.
javax.servlet.ServletResponse#setLocale() sets not only the specified locale,
but also the resonse character encoding suitable for it.
The character encoding setting is dependent on the servlet container.

If the container is Tomcat 4, you can modify the following resource,
org.apache.catalina.util.CharsetMapperDefault.properties in Catalina APIs.

Regards,

 



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




periodic refresh with JSTL c:import

2002-12-18 Thread Brian Buckley
This snippet prints out up-to-date information but it is slow ...

c:import url=channel.jsp 
 c:param name=rssUrl value=http://www.slowurl.rss; /
/c:import

This snippet makes it fast but stale...

c:import url=channel.jsp var=x scope=application 
 c:param name=rssUrl value=http://www.slowurl.rss; /
/c:import
c:out value=${applicationScope.x} escapeXml=false /

How can one use JSTL to do something in between, such as to update the
c:import once an hour?

c:if test=??? test if applicationScope.x is more than an hour old ???
c:import url=channel.jsp var=x scope=application 
 c:param name=rssUrl value=http://www.slowurl.rss; /
/c:import
/c:if
c:out value=${applicationScope.x} escapeXml=false /

Brian





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




Re: periodic refresh with JSTL c:import

2002-12-18 Thread Shawn Bayern
On Wed, 18 Dec 2002, Brian Buckley wrote:

 How can one use JSTL to do something in between, such as to update the
 c:import once an hour?
 
 c:if test=??? test if applicationScope.x is more than an hour old ???
 c:import url=channel.jsp var=x scope=application 
  c:param name=rssUrl value=http://www.slowurl.rss; /
 /c:import
 /c:if
 c:out value=${applicationScope.x} escapeXml=false /

You could create a Date object and compare the time property of this
object against the current time; Hans has shown how to do this in previous
messages.

It might be easier to use the Cache Taglib, which isn't part of JSTL but
does exactly what you're looking for.

-- 
Shawn Bayern
JSTL in Action   http://www.manning.com/bayern


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




periodic refresh with JSTL c:import

2002-12-18 Thread Brian Buckley
Correction -- I meant to include an c:if clause around the fast but stale
way.

c:if test=${empty applicationScope.x}
c:import url=channel.jsp var=x scope=application 
 c:param name=rssUrl value=http://www.slowurl.rss; /
/c:import
/c:if
c:out value=${applicationScope.x} escapeXml=false /

Thanks.




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




Re: periodic refresh with JSTL c:import

2002-12-18 Thread Brian Buckley
 You could create a Date object and compare the time property of this
 object against the current time; Hans has shown how to do this in previous
 messages.

 It might be easier to use the Cache Taglib, which isn't part of JSTL but
 does exactly what you're looking for.

Thanks, Shawn.  I found the Hans example and it does just what I need.

In case you failed to notice :), my snippets were lifted from JSTL In
Action.  Excellent book.



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




Re: c:set can't set JavaBean property

2002-12-18 Thread Mike Cantrell
Okay, I think the problem is that my getter method returns a String but 
the setterMethod takes an integer:

   public String getDay();
   public void setDay(int day);

If I change it to return an integer, it works fine.. I find this 
especially weird since getDay() isn't ever called in any of the code.

Syntactically, it's a bad decision on my part because the getter method 
really should return an int (since it was originally set with an int) 
and if I want it as a String (to pad the zeros for instance), I should 
have a seperate method like:

   public String getFormattedDay();

I guess the real question is; should this condition cause the c:set 
tag to throw an Exception or not?  Then again, maybe I'm completely off 
base and that's not what's causing the problem at all. Check out the 
below JSP code. Try switching the commented code with the un-commented 
code and see if you can re-create the error.


==
%@ page import=java.util.*, java.text.* %
%@ taglib prefix=c uri=http://java.sun.com/jstl/core; %

h3 Test lt;c:setgt;/h3
%!
   public class Foo {
   Date date = new Date();
  
   //public String getDay() {
   //SimpleDateFormat fmt = new SimpleDateFormat(dd);
   //return fmt.format(date);   
   //}
  
   public int getDay() {
   return 1;
   }
  
   public void setDay(int day) {
   System.out.println(Day:  +day);
   System.out.println(date);
   GregorianCalendar cal = new GregorianCalendar();
   cal.setTime(date);
  
   int max = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
   day = (day  max) ? max : day;
  
   cal.set(Calendar.DAY_OF_MONTH, day);
   date = cal.getTime();
   }
  
   public Date getDate() {
   return date;
   }
   }
%

%
   Foo foo = new Foo();
   pageContext.setAttribute(foo, foo);
%

c:out value=${foo.date}/br
c:set target=${foo} property=day value=1/
c:out value=${foo.date}/
===



Pierre Delisle wrote:

Mike,

This NullPointerException is caused by the fact that a write method does not exist
in your bean for property 'day'. 

For example, this would happen if you had a getDay() method, but not
a setDay() method on your bean.

However, from the code snippet you've sent, it looks like that property
is defined... but the VM says it is not. In these situations I tend
to trust the VM rather than the programmer :-)

So... Why don't you isolate your problem in a single JSP file that you
could send to this alias. If we have the full story, it will be easier
to help you debug this problem.

I've included below the test I ran and which worked for me.

   -- Pierre

[I'll file a bug so that a proper error message is returned when
this situation occurs (rather than the NPE)]

-

%@ page import=java.util.* %
%@ taglib prefix=c uri=http://java.sun.com/jstl/core; %

h3 Test lt;c:setgt;/h3
%!
   public class Foo {
 Date date = new Date();

 public void setDay(int day) {
   GregorianCalendar cal = new GregorianCalendar();
   cal.setTime(date);

   int max = cal.getMaximum(Calendar.DAY_OF_MONTH);
   day = (day  max) ? max : day;

   cal.set(Calendar.DAY_OF_MONTH, day);
   date = cal.getTime();
 }

 public Date getDate() {
   return date;
 }
   }
%

%
   Foo foo = new Foo();
   pageContext.setAttribute(foo, foo);
%

c:out value=${foo.date}/br
c:set target=${foo} property=day value=1/
c:out value=${foo.date}/

---


Mike Cantrell wrote:
 

I'm seeing some really strange problems while trying to use JSTL's
c:set action to set a property of a JavaBean. It's throwing a
NullPointerException (see below for stackTrace).

It doesn't like to set my property day. If I create a setter method
with a different name (day2 for instance), which simply calls the
original setter method (day), everything works fine (code included below).

I'm a bit stumped. Maybe I'm missing something obvious here but I'm just
not seeing what the problem is. Can anyone offer any advice?

JSP:
===

jsp:useBean class=com.alcatel.date.AlaDate id=start scope=request/
jsp:useBean class=com.alcatel.date.AlaDate id=end scope=request/

c:choose
 c:when test=${param.mode eq 'month'}
  c:set target=${start} property=deltaMonth value=-1/
  %-- c:set target=${start} property=day value=1/  --%
  c:set target=${start} property=day2 value=1/

  c:set target=${end} property=deltaMonth value=-1/
  %-- c:set target=${end} property=day value=31/ --%
  c:set target=${end} property=day2 value=31/
 /c:when
 c:otherwise
  c:set target=${start} property=deltaDay value=-7/
 /c:otherwise
/c:choose

JavaBean:
===

  public void setDay(int day) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);

int max = cal.getMaximum(Calendar.DAY_OF_MONTH);
day = (day  max) ? 

Re: c:set can't set JavaBean property

2002-12-18 Thread Hans Bergsten
Mike Cantrell wrote:

Okay, I think the problem is that my getter method returns a String but 
the setterMethod takes an integer:

   public String getDay();
   public void setDay(int day);

If I change it to return an integer, it works fine.. I find this 
especially weird since getDay() isn't ever called in any of the code.
 [...]

That's the problem, and it doesn't matter if you call one or the other
or not. The JavaBeans rules that defines what's a property says that
both the getter and the setter must be of the same type, if they are
both implemented.

Hans
--
Hans Bergsten[EMAIL PROTECTED]
Gefion Software   http://www.gefionsoftware.com/
Author of O'Reilly's JavaServer Pages, covering JSP 1.2 and JSTL 1.0
Details athttp://TheJSPBook.com/


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