You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by אלחנן מעין <em...@msn.com> on 2007/05/06 08:45:56 UTC

attempting to use time Converter?

hi...

i've created a string to time Conversion:

public Object convertValue(Map ctx, Object value, Class toType) {

		if(toType==String.class){
			return convert((Date) value);
		}
		if(toType==Date.class){
			String s=((String[])value)[0];
			return  convert(s);
		}
		return null;
	}
	protected Date convert(String v) {
		final Calendar calendar=new GregorianCalendar();
		if (v.indexOf(':')>0){
			calendar.set(Calendar.HOUR_OF_DAY,new Integer(v.split(":")[0]));
			calendar.set(Calendar.MINUTE,new Integer(v.split(":")[1]));
			return calendar.getTime();
		}
		return null;
	}

	protected String convert(Date value){
		final Calendar calendar=new GregorianCalendar();
		calendar.setTime( value==null ? new Date(): value);
		String s=calendar.get(Calendar.HOUR_OF_DAY)+ 
":"+calendar.get(Calendar.MINUTE);
		return s;
	}

i linked it a spefici field in the properties files of an action 
(reportHours-conversion.properties)
the problem begins when i define properties in Date type in the action, the 
convertor sends the string correctly to the Time Picker which DOESN'T 
display it, if i try typeing the same time, and move to the next field the 
values i clicked vanishes, BUT if i choose the same value from time picker's 
drop down, it's ok... should i loose the time picker completly??

_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! 
http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: attempting to use time Converter?

Posted by Martin Gainty <mg...@hotmail.com>.
assuming your stack param is Date value this statement is causing exception
String s=((String[])value)[0];

you need to either use DateFormat.toString()
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DateFormat.html

OR date.toString() e.g.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#toString()

Martin--
This email message and any files transmitted with it contain confidential
information intended only for the person(s) to whom this email message is
addressed.  If you have received this email message in error, please notify
the sender immediately by telephone or email and destroy the original
message without making a copy.  Thank you.

----- Original Message ----- 
From: "א×o×-× ×Y ×z×¢×T×Y" <em...@msn.com>
To: <us...@struts.apache.org>
Sent: Sunday, May 06, 2007 2:45 AM
Subject: attempting to use time Converter?


> hi...
>
> i've created a string to time Conversion:
>
> public Object convertValue(Map ctx, Object value, Class toType) {
>
> if(toType==String.class){
> return convert((Date) value);
> }
> if(toType==Date.class){
> String s=((String[])value)[0];
> return  convert(s);
> }
> return null;
> }
> protected Date convert(String v) {
> final Calendar calendar=new GregorianCalendar();
> if (v.indexOf(':')>0){
> calendar.set(Calendar.HOUR_OF_DAY,new Integer(v.split(":")[0]));
> calendar.set(Calendar.MINUTE,new Integer(v.split(":")[1]));
> return calendar.getTime();
> }
> return null;
> }
>
> protected String convert(Date value){
> final Calendar calendar=new GregorianCalendar();
> calendar.setTime( value==null ? new Date(): value);
> String s=calendar.get(Calendar.HOUR_OF_DAY)+ 
> ":"+calendar.get(Calendar.MINUTE);
> return s;
> }
>
> i linked it a spefici field in the properties files of an action 
> (reportHours-conversion.properties)
> the problem begins when i define properties in Date type in the action, 
> the convertor sends the string correctly to the Time Picker which DOESN'T 
> display it, if i try typeing the same time, and move to the next field the 
> values i clicked vanishes, BUT if i choose the same value from time 
> picker's drop down, it's ok... should i loose the time picker completly??
>
> _________________________________________________________________
> FREE pop-up blocking with the new MSN Toolbar - get it now! 
> http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org