You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Gerolf Seitz <ge...@gmail.com> on 2007/09/24 00:09:41 UTC

add DateFormat for DateValidator

i was wondering if we could provide the facilities to set a
DateFormat/-Pattern (to format the date in feedback messages) for
DateValidators?
the default format in a feedback message via toString() (like "Sun Sep 23
23:59:55 CEST 2007") seems rather strange,
when the user needed to enter a date in a different format (which he
probably will).

i was thinking of the following:

add "DateValidator withDateFormat(DateFormat format)" and "DateValidator
withDatePattern(String pattern)" to DateValidator.
every DateValidator (Range, Minimum, Maximum) should add the variable values
like this:

protected Map variablesMap(IValidatable validatable)
        {
            final Map map = super.variablesMap(validatable);
            map.put("maximum", formatDate(maximum)); // use formatDate(Date)
            return map;
        }

the formatDate method either uses the provided dateformat to format the date
or otherwise (in case no dateformat/patter was provided) just returns the
result of the toString() method.

so, wdyt?

  gerolf

Re: add DateFormat for DateValidator

Posted by Martijn Dashorst <ma...@gmail.com>.
On 9/26/07, Andrew Klochkov <a....@webalta-team.com> wrote:
> PS is it ok to write here if I'm not a wicket team member?

How else would you expect to become a team member? :-)

Yep as long as it pertains development issues related to Wicket
core/stuff projects, anyone can chip in.

Martijn

-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta3 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta3/

Re: add DateFormat for DateValidator

Posted by Andrew Klochkov <a....@webalta-team.com>.
Hi,

Just my 5 cents: it's not good to serialize SimpleDateFormat instances 
as part of the page state because IMHO it's footprint is too big. So 
please avoid it or at least make it possible to store just a pattern (as 
Gerolf suggested).

BTW don't you think that wicket needs some profiling tool to make it 
easier to reduce pagemaps and sessions size by viewing pages state 
contents in some convenient way? AFAIK there was a JIRA issue for this - 
does it still exist and what's its state?

PS is it ok to write here if I'm not a wicket team member?

Gerolf Seitz wrote:
> i was wondering if we could provide the facilities to set a
> DateFormat/-Pattern (to format the date in feedback messages) for
> DateValidators?
> the default format in a feedback message via toString() (like "Sun Sep 23
> 23:59:55 CEST 2007") seems rather strange,
> when the user needed to enter a date in a different format (which he
> probably will).
>
> i was thinking of the following:
>
> add "DateValidator withDateFormat(DateFormat format)" and "DateValidator
> withDatePattern(String pattern)" to DateValidator.
> every DateValidator (Range, Minimum, Maximum) should add the variable values
> like this:
>
> protected Map variablesMap(IValidatable validatable)
>         {
>             final Map map = super.variablesMap(validatable);
>             map.put("maximum", formatDate(maximum)); // use formatDate(Date)
>             return map;
>         }
>
> the formatDate method either uses the provided dateformat to format the date
> or otherwise (in case no dateformat/patter was provided) just returns the
> result of the toString() method.
>
> so, wdyt?
>
>   gerolf
>
>   


-- 
Andrew Klochkov


Re: add DateFormat for DateValidator

Posted by Igor Vaynberg <ig...@gmail.com>.
i think the best place to do this is actually in
ivalidationerror.geterrormessage() and pass in an additional argument that
is some iconverter { String toString(Object o); }

is it too late to change that interface?

-igor


On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> right, that is what i meant also
>
> -igor
>
>
> On 9/25/07, Eelco Hillenius <eelco.hillenius@gmail.com > wrote:
> >
> > On 9/25/07, Gerolf Seitz <gerolf.seitz@gmail.com > wrote:
> > > my proposed solution can be found at [0].
> > > basically, iterate over all error variables and convert the variables,
> > that
> > > are of type FormComponent#getType, using the FormComponent's
> > converter.
> > >
> > > [0] http://www.papernapkin.org/pastebin/view/4228
> >
> > How about turning it around and doing something like
> > getConverter(value) for all the values in there? Then it would work
> > for all the variables in there, even if they are not the same type of
> > the component.
> >
> > Eelco
> >
>
>

Re: add DateFormat for DateValidator

Posted by Igor Vaynberg <ig...@gmail.com>.
right, that is what i meant also

-igor


On 9/25/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 9/25/07, Gerolf Seitz <ge...@gmail.com> wrote:
> > my proposed solution can be found at [0].
> > basically, iterate over all error variables and convert the variables,
> that
> > are of type FormComponent#getType, using the FormComponent's converter.
> >
> > [0] http://www.papernapkin.org/pastebin/view/4228
>
> How about turning it around and doing something like
> getConverter(value) for all the values in there? Then it would work
> for all the variables in there, even if they are not the same type of
> the component.
>
> Eelco
>

Re: add DateFormat for DateValidator

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/25/07, Gerolf Seitz <ge...@gmail.com> wrote:
> my proposed solution can be found at [0].
> basically, iterate over all error variables and convert the variables, that
> are of type FormComponent#getType, using the FormComponent's converter.
>
> [0] http://www.papernapkin.org/pastebin/view/4228

How about turning it around and doing something like
getConverter(value) for all the values in there? Then it would work
for all the variables in there, even if they are not the same type of
the component.

Eelco

Re: add DateFormat for DateValidator

Posted by Gerolf Seitz <ge...@gmail.com>.
my proposed solution can be found at [0].
basically, iterate over all error variables and convert the variables, that
are of type FormComponent#getType, using the FormComponent's converter.

[0] http://www.papernapkin.org/pastebin/view/4228

  gerolf

On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> gerolf get on top of that and let us know how it works out :)
>
> -igor
>
>
> On 9/25/07, Eelco Hillenius <ee...@gmail.com> wrote:
> >
> > On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > > we could just make whatever variables error has first run through the
> > > component's converter
> > >
> > > that way it will use the same dateformat...
> >
> > Yeah, that sounds like an idea.
> >
> > Eelco
> >
>

Re: add DateFormat for DateValidator

Posted by Igor Vaynberg <ig...@gmail.com>.
gerolf get on top of that and let us know how it works out :)

-igor


On 9/25/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > we could just make whatever variables error has first run through the
> > component's converter
> >
> > that way it will use the same dateformat...
>
> Yeah, that sounds like an idea.
>
> Eelco
>

Re: add DateFormat for DateValidator

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
> we could just make whatever variables error has first run through the
> component's converter
>
> that way it will use the same dateformat...

Yeah, that sounds like an idea.

Eelco

Re: add DateFormat for DateValidator

Posted by Igor Vaynberg <ig...@gmail.com>.
we could just make whatever variables error has first run through the
component's converter

that way it will use the same dateformat...

-igor


On 9/25/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > what he has as an example seems fine to me.
>
> I haven't looked into it much, but thought you might already have
> something for similar cases. If not, we'd probably also need it for
> numbers, right?
>
> Eelco
>

Re: add DateFormat for DateValidator

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/25/07, Igor Vaynberg <ig...@gmail.com> wrote:
> what he has as an example seems fine to me.

I haven't looked into it much, but thought you might already have
something for similar cases. If not, we'd probably also need it for
numbers, right?

Eelco

Re: add DateFormat for DateValidator

Posted by Igor Vaynberg <ig...@gmail.com>.
what he has as an example seems fine to me.

-igor


On 9/25/07, Eelco Hillenius <ee...@gmail.com> wrote:
>
> On 9/23/07, Gerolf Seitz <ge...@gmail.com> wrote:
> > i was wondering if we could provide the facilities to set a
> > DateFormat/-Pattern (to format the date in feedback messages) for
> > DateValidators?
> > the default format in a feedback message via toString() (like "Sun Sep
> 23
> > 23:59:55 CEST 2007") seems rather strange,
> > when the user needed to enter a date in a different format (which he
> > probably will).
> >
> > i was thinking of the following:
> >
> > add "DateValidator withDateFormat(DateFormat format)" and "DateValidator
> > withDatePattern(String pattern)" to DateValidator.
> > every DateValidator (Range, Minimum, Maximum) should add the variable
> values
> > like this:
> >
> > protected Map variablesMap(IValidatable validatable)
> >         {
> >             final Map map = super.variablesMap(validatable);
> >             map.put("maximum", formatDate(maximum)); // use
> formatDate(Date)
> >             return map;
> >         }
> >
> > the formatDate method either uses the provided dateformat to format the
> date
> > or otherwise (in case no dateformat/patter was provided) just returns
> the
> > result of the toString() method.
> >
> > so, wdyt?
>
> Not sure, though I have a hunch Igor has an idea how this should be
> done without a new API.
>
> Eelco
>

Re: add DateFormat for DateValidator

Posted by Eelco Hillenius <ee...@gmail.com>.
On 9/23/07, Gerolf Seitz <ge...@gmail.com> wrote:
> i was wondering if we could provide the facilities to set a
> DateFormat/-Pattern (to format the date in feedback messages) for
> DateValidators?
> the default format in a feedback message via toString() (like "Sun Sep 23
> 23:59:55 CEST 2007") seems rather strange,
> when the user needed to enter a date in a different format (which he
> probably will).
>
> i was thinking of the following:
>
> add "DateValidator withDateFormat(DateFormat format)" and "DateValidator
> withDatePattern(String pattern)" to DateValidator.
> every DateValidator (Range, Minimum, Maximum) should add the variable values
> like this:
>
> protected Map variablesMap(IValidatable validatable)
>         {
>             final Map map = super.variablesMap(validatable);
>             map.put("maximum", formatDate(maximum)); // use formatDate(Date)
>             return map;
>         }
>
> the formatDate method either uses the provided dateformat to format the date
> or otherwise (in case no dateformat/patter was provided) just returns the
> result of the toString() method.
>
> so, wdyt?

Not sure, though I have a hunch Igor has an idea how this should be
done without a new API.

Eelco