You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Ben Peter <bp...@zentropypartners.com> on 2002/04/12 09:03:26 UTC

Examples of hadling date input

Hi,

browsing through the turbine2 and fulcrum java docs I have found two things 
that provide help with handling date input:

http://jakarta.apache.org/turbine/turbine-2/apidocs/org/apache/turbine/util/DateSelector.html
http://jakarta.apache.org/turbine/fulcrum/apidocs/org/apache/fulcrum/intake/model/DateStringField.html

Has anyone used intake and/or the DateSelector and can provide a simple example 
of how to use them?

If no and there is interest, I will investigate and post it back here.

(I realise that this is probably nothing very sophisticated, but I always find 
it a tedious task to figure out how date input is best handled).

Cheers,
Ben

-- 
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Examples of hadling date input

Posted by Ben Peter <bp...@zentropypartners.com>.
James,

thanks for your reply, this has put me on the right track.

I have now augmented the DateSelector a bit, so that it can be easily used for 
getting the submitted date/calendar back. Also, it handles Locales 
automatically now, based on either the information in RunData if you use the 
new DateSelector(myName, myCalendar, runData) ctor, or if you call 
ds.setLocale(myLocale). This behaviour can be suppressed by calling 
ds.setUseLocale(false). (Or simply leaving the new ctor and setLocale() alone).

If you are interested, the patch is available in the turbine-dev archives:
http://nagoya.apache.org:8080/eyebrowse/ReadMsg?listName=turbine-dev@jakarta.apache.org&msgNo=4424

Cheers,
Ben

James Cooper wrote:
> Hi Ben,
> Well it is one of the most trivial things, but in the end it was kinda
> labourious. Heres a quick and dirty way I implemented it, it you come up or
> anyone else comes up with something a little cleaner by all means join the
> discussion.
> 
> I basically sent the DateSelector object to the screen, had problems
> localising it to a European date format Day/Month/Year
> 
> Putting it to the screen with the current date:
> ElementContainer dateSelect = new ElementContainer();
> Calendar calendar = new GregorianCalendar();
> 
> Date myStartDate = new Date();
> calendar.setTime(myStartDate);
> Locale myLocale = new Locale("ENGLISH", "UK");
> calendar = calendar.getInstance(myLocale);
> 
> DateSelector ds = new DateSelector("fromDate", calendar);
> dateSelect = ds.ecsOutput();
> 
> I then grab the resulting generating code using the:
> String lmnthStartDate = data.getParameters().getString("fromDate_month");
> String ldayStartDate = data.getParameters().getString("fromDate_day");
> String lyearStartDate = data.getParameters().getString("fromDate_year");
> 
> Then I form a string and convert this into a date:
> ParsePosition pos = new ParsePosition(0);
> String lStrDate = ldayStartDate+"/"+strMnthStartDate+"/"+lyearStartDate;
> 
> Date myStartDate = formatter.parse(lStrDate, pos);
> 
> 
> This is a little rough and very much a cut n paste effort. But I'm sure you
> get my drift...if you come across with anything better let me know.
> 
> 
> -----Original Message-----
> From: Ben Peter [mailto:bpeter@zentropypartners.com]
> Sent: 12 April 2002 09:03
> To: turbine-user@jakarta.apache.org
> Subject: Examples of hadling date input
> 
> 
> Hi,
> 
> browsing through the turbine2 and fulcrum java docs I have found two things
> that provide help with handling date input:
> 
> http://jakarta.apache.org/turbine/turbine-2/apidocs/org/apache/turbine/util/
> DateSelector.html
> http://jakarta.apache.org/turbine/fulcrum/apidocs/org/apache/fulcrum/intake/
> model/DateStringField.html
> 
> Has anyone used intake and/or the DateSelector and can provide a simple
> example
> of how to use them?
> 
> If no and there is interest, I will investigate and post it back here.
> 
> (I realise that this is probably nothing very sophisticated, but I always
> find
> it a tedious task to figure out how date input is best handled).
> 
> Cheers,
> Ben
> 
> --
> Benjamin Peter                                          +49-69-96244395
> Application Engineer                             Moerfelder Landstr. 55
> (zentropy:partners)                            60598 Frankfurt, Germany
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>



-- 
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Examples of hadling date input

Posted by Diederik de Groot <dd...@talon.nl>.
Hi there Ben,

Thanks for the suggestions. I'll have to look into that patch and see how
that could work for my applicationTool. I like to implement everything in
applicationTools so other people can do the velocity stuff. I just want to
provide them with the corretc data. I really do not want to be programming
java classes for all the pages they can come up with only to provide them
with a dateSelector. I was thinking of implementing locals in my application
as well, but this have to figure out where to begin updating :-)

Thanks for the comment,

Diederik

> -----Original Message-----
> From: Ben Peter [mailto:bpeter@zentropypartners.com]
> Sent: zondag 14 april 2002 3:02
> To: Turbine Users List
> Subject: Re: Examples of hadling date input
>
>
> Diederik,
>
> thanks a lot for the code example. I expect it works seamlessly.
>
> What bothered be most about handling dates is that the result of the
> DateSelector cannot be it's input - only if you put together a
> String and then
> parse it. That is why I have augmented the DateSelector to allow
> this, along
> with some other enhancements.
>
> I have added the possibility to read the results of the posted
> selector back
> in. The Calendar object in the DateSelector is adjusted to the
> new date. It
> also provieds a method to retrieve that Calendar, so that you can
> do the following:
>
> // in the Screen
> DateSelector ds = new DateSelector("myDate",
> Calendar.getInstance(), runData);
> context.put("ds", ds);
>
> ## in the template
> <form action="...">$ds<input type="submit"/></form>
>
> // in the Action (or back in the same screen)
> DateSelector ds = new DateSelector("myDate",
> Calendar.getInstance(), runData);
> Calendar result = ds.getCalendar();
>
> This last part might look a bit confusing. The behaviout of the
> ctor is the
> following:
>
> - set the internal calendar to the calendar passed
> - *set the internal locale (use for month names) to runData.getLocale()
> - override the fields in the calendar with submitted information, if any.
>
> * the locale-thing is a bit pointless, as in t2 the
> TurbineRunDataService does
> not put locale information into runData, you would need to call a
> runData.setLocale(runData.getRequest().getLocale()) handish.
>
>
> The patch is at
> http://nagoya.apache.org:8080/eyebrowse/ReadMsg?listName=turbine-d
ev@jakarta.apache.org&msgNo=4424

and a further description in this very thread at
http://nagoya.apache.org:8080/eyebrowse/ReadMsg?listName=turbine-user@jakart
a.apache.org&msgNo=3326

Cheers,
Ben

Diederik de Groot wrote:
> Hi Ben,
>
> You could implement it as an application tool so you can use it from
> Velocity directly.
>
>


>>
>> Has anyone used intake and/or the DateSelector and can provide a simple
>> example
>> of how to use them?
>>
--
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Examples of hadling date input

Posted by Ben Peter <bp...@zentropypartners.com>.
Diederik,

thanks a lot for the code example. I expect it works seamlessly.

What bothered be most about handling dates is that the result of the 
DateSelector cannot be it's input - only if you put together a String and then 
parse it. That is why I have augmented the DateSelector to allow this, along 
with some other enhancements.

I have added the possibility to read the results of the posted selector back 
in. The Calendar object in the DateSelector is adjusted to the new date. It 
also provieds a method to retrieve that Calendar, so that you can do the following:

// in the Screen
DateSelector ds = new DateSelector("myDate", Calendar.getInstance(), runData);
context.put("ds", ds);

## in the template
<form action="...">$ds<input type="submit"/></form>

// in the Action (or back in the same screen)
DateSelector ds = new DateSelector("myDate", Calendar.getInstance(), runData);
Calendar result = ds.getCalendar();

This last part might look a bit confusing. The behaviout of the ctor is the 
following:

- set the internal calendar to the calendar passed
- *set the internal locale (use for month names) to runData.getLocale()
- override the fields in the calendar with submitted information, if any.

* the locale-thing is a bit pointless, as in t2 the TurbineRunDataService does 
not put locale information into runData, you would need to call a
runData.setLocale(runData.getRequest().getLocale()) handish.


The patch is at
http://nagoya.apache.org:8080/eyebrowse/ReadMsg?listName=turbine-dev@jakarta.apache.org&msgNo=4424

and a further description in this very thread at
http://nagoya.apache.org:8080/eyebrowse/ReadMsg?listName=turbine-user@jakarta.apache.org&msgNo=3326

Cheers,
Ben

Diederik de Groot wrote:
> Hi Ben,
> 
> You could implement it as an application tool so you can use it from
> Velocity directly.
> 
> 


>> 
>> Has anyone used intake and/or the DateSelector and can provide a simple
>> example
>> of how to use them?
>> 
-- 
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Examples of hadling date input

Posted by Diederik de Groot <dd...@talon.nl>.
Hi Ben,

You could implement it as an application tool so you can use it from
Velocity directly.


package nl.golfmetmij.matcher.om.tools;

/*
 *  ====================================================================
 *  Copyright (c) 2001 Talon.  All rights reserved.
 *
 *  ====================================================================
 */

// JDK classes
import java.util.*;
import java.math.*;
import java.text.SimpleDateFormat;
import java.text.ParseException;

// Turbine classes
import org.apache.turbine.services.pull.*;
import org.apache.turbine.services.cache.*;
import org.apache.turbine.util.db.*;
import org.apache.turbine.util.*;

// Torque classes
import org.apache.torque.util.Criteria;
import org.apache.torque.om.*;
import org.apache.torque.util.*;

// Object Model classes
import nl.golfmetmij.matcher.om.*;


/**
 * Contains Velocity pullable utilities like dateSelector Implementation
 *
 * [Fri Apr 12 16:50:12 CEST 2002]
 *
 * @author     <a href="mailto://ddegroot@talon.nl">Diederik de Groot</a>
 * @created    Copyright 2002 <a href="http://www.talon.nl">Talon</a>
 *
 */
public abstract class UtilTool implements ApplicationTool {

	public String getDateSelector(Date myDate, String elementName)
	{
		Calendar calendar = new GregorianCalendar();

		calendar.setTime(myDate);
		Locale myLocale = new Locale("DUTCH", "NL");
		calendar = calendar.getInstance(myLocale);

		DateSelector ds = new DateSelector(elementName, calendar);
		return ds.ecsOutput().toString();
	}

	public Date getDateFromSelector(ParameterParser parameters, String
elementName)
	{
		Date myDate = new Date();
		String strMnthStartDate = parameters.getString(elementName+"_month");
		String strDayStartDate = parameters.getString(elementName+"_day");
		String strYearStartDate = parameters.getString(elementName+"_year");

		try
		{
			SimpleDateFormat dateFormat= new SimpleDateFormat ("yyyy-MM-dd");
			myDate =
dateFormat.parse(strYearStartDate+"-"+strMnthStartDate+"-"+strMnthStartDate)
;
		}
		catch (ParseException e)
		{
			Log.info("Date from Selector could not be parsed");
		}

		return myDate;
	}
}

That should work,

Diederik de Groot
Talon v.o.f.
www.talon.nl
ddegroot@talon.nl



> -----Original Message-----
> From: James Cooper [mailto:james.cooper@maxware.nl]
> Sent: vrijdag 12 april 2002 10:41
> To: Turbine Users List
> Subject: RE: Examples of hadling date input
>
>
> Hi Ben,
> Well it is one of the most trivial things, but in the end it was kinda
> labourious. Heres a quick and dirty way I implemented it, it you
> come up or
> anyone else comes up with something a little cleaner by all means join the
> discussion.
>
> I basically sent the DateSelector object to the screen, had problems
> localising it to a European date format Day/Month/Year
>
> Putting it to the screen with the current date:
> ElementContainer dateSelect = new ElementContainer();
> Calendar calendar = new GregorianCalendar();
>
> Date myStartDate = new Date();
> calendar.setTime(myStartDate);
> Locale myLocale = new Locale("ENGLISH", "UK");
> calendar = calendar.getInstance(myLocale);
>
> DateSelector ds = new DateSelector("fromDate", calendar);
> dateSelect = ds.ecsOutput();
>
> I then grab the resulting generating code using the:
> String lmnthStartDate = data.getParameters().getString("fromDate_month");
> String ldayStartDate = data.getParameters().getString("fromDate_day");
> String lyearStartDate = data.getParameters().getString("fromDate_year");
>
> Then I form a string and convert this into a date:
> ParsePosition pos = new ParsePosition(0);
> String lStrDate = ldayStartDate+"/"+strMnthStartDate+"/"+lyearStartDate;
>
> Date myStartDate = formatter.parse(lStrDate, pos);
>
>
> This is a little rough and very much a cut n paste effort. But
> I'm sure you
> get my drift...if you come across with anything better let me know.
>
>
> -----Original Message-----
> From: Ben Peter [mailto:bpeter@zentropypartners.com]
> Sent: 12 April 2002 09:03
> To: turbine-user@jakarta.apache.org
> Subject: Examples of hadling date input
>
>
> Hi,
>
> browsing through the turbine2 and fulcrum java docs I have found
> two things
> that provide help with handling date input:
>
> http://jakarta.apache.org/turbine/turbine-2/apidocs/org/apache/tur
bine/util/
DateSelector.html
http://jakarta.apache.org/turbine/fulcrum/apidocs/org/apache/fulcrum/intake/
model/DateStringField.html

Has anyone used intake and/or the DateSelector and can provide a simple
example
of how to use them?

If no and there is interest, I will investigate and post it back here.

(I realise that this is probably nothing very sophisticated, but I always
find
it a tedious task to figure out how date input is best handled).

Cheers,
Ben

--
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Examples of hadling date input

Posted by James Cooper <ja...@maxware.nl>.
Hi Ben,
Well it is one of the most trivial things, but in the end it was kinda
labourious. Heres a quick and dirty way I implemented it, it you come up or
anyone else comes up with something a little cleaner by all means join the
discussion.

I basically sent the DateSelector object to the screen, had problems
localising it to a European date format Day/Month/Year

Putting it to the screen with the current date:
ElementContainer dateSelect = new ElementContainer();
Calendar calendar = new GregorianCalendar();

Date myStartDate = new Date();
calendar.setTime(myStartDate);
Locale myLocale = new Locale("ENGLISH", "UK");
calendar = calendar.getInstance(myLocale);

DateSelector ds = new DateSelector("fromDate", calendar);
dateSelect = ds.ecsOutput();

I then grab the resulting generating code using the:
String lmnthStartDate = data.getParameters().getString("fromDate_month");
String ldayStartDate = data.getParameters().getString("fromDate_day");
String lyearStartDate = data.getParameters().getString("fromDate_year");

Then I form a string and convert this into a date:
ParsePosition pos = new ParsePosition(0);
String lStrDate = ldayStartDate+"/"+strMnthStartDate+"/"+lyearStartDate;

Date myStartDate = formatter.parse(lStrDate, pos);


This is a little rough and very much a cut n paste effort. But I'm sure you
get my drift...if you come across with anything better let me know.


-----Original Message-----
From: Ben Peter [mailto:bpeter@zentropypartners.com]
Sent: 12 April 2002 09:03
To: turbine-user@jakarta.apache.org
Subject: Examples of hadling date input


Hi,

browsing through the turbine2 and fulcrum java docs I have found two things
that provide help with handling date input:

http://jakarta.apache.org/turbine/turbine-2/apidocs/org/apache/turbine/util/
DateSelector.html
http://jakarta.apache.org/turbine/fulcrum/apidocs/org/apache/fulcrum/intake/
model/DateStringField.html

Has anyone used intake and/or the DateSelector and can provide a simple
example
of how to use them?

If no and there is interest, I will investigate and post it back here.

(I realise that this is probably nothing very sophisticated, but I always
find
it a tedious task to figure out how date input is best handled).

Cheers,
Ben

--
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>