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:[EMAIL PROTECTED]";>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
[EMAIL PROTECTED]



> -----Original Message-----
> From: James Cooper [mailto:[EMAIL PROTECTED]]
> 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:[EMAIL PROTECTED]]
> Sent: 12 April 2002 09:03
> To: [EMAIL PROTECTED]
> 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:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



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


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

Reply via email to