Re: [appfuse-user] Re: Dates: display - bind (Newbie) - PROBLEM HAS BEEN SOLVED

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [appfuse-user] Re: Dates: display - bind (Newbie) - PROBLEM HAS BEEN SOLVED

Gilberto C Andrade
Ernesto,
 Suppose we have a form (register) with 2 dates: first one you want just
date (dtCreate) and the other date and time (dtHrUpdate).
 In my country's date format is:
 ApplicationResources_pt_BR.properties: date.format=dd/MM/yyyy
 BaseFormController:
        SimpleDateFormat dateFormat = new
SimpleDateFormat(getText("date.format", request.getLocale()));
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, null, new
CustomDateEditor(dateFormat, true));

So, this is the default config!
One thing that not come with appfuse and you can put is:
ApplicationResources_pt_BR.properties:
        # -- validator errors --
        typeMismatch.java.lang.Integer={0} n?o ? um n?mero v?lido.
        typeMismatch.java.lang.Double={0} n?o ? um n?mero v?lido.
        typeMismatch.java.util.Date={0} n?o ? uma data v?lida (dd/MM/yyyy).
        typeMismatch.java.util.Time={0} n?o ? uma hora v?lida (HH:mm:ss).
Until now we deal with date field only. Now in your form you need to
override initBinder method, to register your dateTime field:
    {
        super.initBinder(request, binder);
        // convert java.util.Date
        SimpleDateFormat dateTimeFormat = new
SimpleDateFormat(getText("_date.time.format_",
request.getLocale()),request.getLocale());
        binder.registerCustomEditor(Date.class, "_dtHrUpdate_", new
CustomDateEditor(dateTimeFormat, true));
    }
and
ApplicationResources_pt_BR.properties:
    # -- general values --
    time.format=HH:mm:ss
    date.time.format=dd/MM/yyyy HH:mm:ss

    # -- Register-START
    # -- register form --
    register.cdRegister=ID
    register.dtCreate=Dt. Create
    register.dtHrUpdate=Dt./Hr. Update
    # -- validator errors --
    typeMismatch.register.dtHrUpdate={0} n?o ? uma data/hora v?lida
(dd/MM/yyyy HH:mm:ss).

That's all!

HDH
Gilberto

> Thank you guys for your answers...
>
> It's been a learning trip all right.
>
> I'm using Spring-Web.
>
> ok, now I'm using fmt:formatDate for displaying the data (thanks for
> the tip, Eric), but keeping the regular c:out inside the bind tag. It
> all had to do with the custom editors, now I'm using 2 separate
> editors for 2 date fields that I have:
> ...
> binder.registerCustomEditor(Date.class, "startTime", new
> CustomDateEditor(DateFormat.getDateTimeInstance(DateFormat.FULL,
> DateFormat.FULL, request.getLocale()),true));
> ...
> for the date-time field and a more simpler:
> ...
> SimpleDateFormat dateFormat = new SimpleDateFormat(getText(
>                 "date.format", request.getLocale()));
> dateFormat.setLenient(false);
> binder.registerCustomEditor(Date.class, "participant.birthDate", new
> CustomDateEditor(dateFormat, true));
> ...
> for the date-only field.
>
> I guess it had to do with a partially "contaminated" bind tag which
> was giving me all the trouble. Aparently the custom editors are the
> ones that control the output format as well, this I hadn't understood
> before.
>
>
> Radim Burget wrote:
>
>> Please, send us which framework are you using. Struts, Spring-web,
>> Tapestry or Webwork ?
>>
>> Ernesto Echeverria wrote:
>>
>>> How do I control the format on which a date displays on the view?
>>>
>>> If a date is initialized in FormBackingObject, it displays in a
>>> particular way.
>>>
>>> e.g.        Sat Jul 23 13:24:06 GMT-06:00 2005
>>>
>>> However if an existing object is retrieved from the database, the
>>> date displays differently...
>>>
>>> e.g.     2005-07-11 00:38:03.0
>>>
>>> How do I exactly control this behavior?
>>>
>>> I'm having trouble sending back dates and I'm interested in a full
>>> format (date & time)...
>>>
>>> I've seen this topic covered and have it figured out in the case of
>>> date only, however can't seem to make it work with time included.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[appfuse-user] Re: Dates: display - bind (Newbie) - PROBLEM HAS BEEN SOLVED

Ernesto Echeverria
Thanks again for this tip. I'll consider this option.

Gilberto C. Andrade wrote:

> Ernesto,
> Suppose we have a form (register) with 2 dates: first one you want just
> date (dtCreate) and the other date and time (dtHrUpdate).
> In my country's date format is:
> ApplicationResources_pt_BR.properties: date.format=dd/MM/yyyy
> BaseFormController:
>        SimpleDateFormat dateFormat = new
> SimpleDateFormat(getText("date.format", request.getLocale()));
>        dateFormat.setLenient(false);
>        binder.registerCustomEditor(Date.class, null, new
> CustomDateEditor(dateFormat, true));
>
> So, this is the default config!
> One thing that not come with appfuse and you can put is:
> ApplicationResources_pt_BR.properties:
>        # -- validator errors --
>        typeMismatch.java.lang.Integer={0} n?o ? um n?mero v?lido.
>        typeMismatch.java.lang.Double={0} n?o ? um n?mero v?lido.
>        typeMismatch.java.util.Date={0} n?o ? uma data v?lida (dd/MM/yyyy).
>        typeMismatch.java.util.Time={0} n?o ? uma hora v?lida (HH:mm:ss).
> Until now we deal with date field only. Now in your form you need to
> override initBinder method, to register your dateTime field:
>    {
>        super.initBinder(request, binder);
>        // convert java.util.Date
>        SimpleDateFormat dateTimeFormat = new
> SimpleDateFormat(getText("_date.time.format_",
> request.getLocale()),request.getLocale());
>        binder.registerCustomEditor(Date.class, "_dtHrUpdate_", new
> CustomDateEditor(dateTimeFormat, true));
>    }
> and
> ApplicationResources_pt_BR.properties:
>    # -- general values --
>    time.format=HH:mm:ss
>    date.time.format=dd/MM/yyyy HH:mm:ss
>
>    # -- Register-START
>    # -- register form --
>    register.cdRegister=ID
>    register.dtCreate=Dt. Create
>    register.dtHrUpdate=Dt./Hr. Update
>    # -- validator errors --
>    typeMismatch.register.dtHrUpdate={0} n?o ? uma data/hora v?lida
> (dd/MM/yyyy HH:mm:ss).
>
> That's all!
>
> HDH
> Gilberto
>
>> Thank you guys for your answers...
>>
>> It's been a learning trip all right.
>>
>> I'm using Spring-Web.
>>
>> ok, now I'm using fmt:formatDate for displaying the data (thanks for
>> the tip, Eric), but keeping the regular c:out inside the bind tag. It
>> all had to do with the custom editors, now I'm using 2 separate
>> editors for 2 date fields that I have:
>> ...
>> binder.registerCustomEditor(Date.class, "startTime", new
>> CustomDateEditor(DateFormat.getDateTimeInstance(DateFormat.FULL,
>> DateFormat.FULL, request.getLocale()),true));
>> ...
>> for the date-time field and a more simpler:
>> ...
>> SimpleDateFormat dateFormat = new SimpleDateFormat(getText(
>>                 "date.format", request.getLocale()));
>> dateFormat.setLenient(false);
>> binder.registerCustomEditor(Date.class, "participant.birthDate", new
>> CustomDateEditor(dateFormat, true));
>> ...
>> for the date-only field.
>>
>> I guess it had to do with a partially "contaminated" bind tag which
>> was giving me all the trouble. Aparently the custom editors are the
>> ones that control the output format as well, this I hadn't understood
>> before.
>>
>>
>> Radim Burget wrote:
>>
>>> Please, send us which framework are you using. Struts, Spring-web,
>>> Tapestry or Webwork ?
>>>
>>> Ernesto Echeverria wrote:
>>>
>>>> How do I control the format on which a date displays on the view?
>>>>
>>>> If a date is initialized in FormBackingObject, it displays in a
>>>> particular way.
>>>>
>>>> e.g.        Sat Jul 23 13:24:06 GMT-06:00 2005
>>>>
>>>> However if an existing object is retrieved from the database, the
>>>> date displays differently...
>>>>
>>>> e.g.     2005-07-11 00:38:03.0
>>>>
>>>> How do I exactly control this behavior?
>>>>
>>>> I'm having trouble sending back dates and I'm interested in a full
>>>> format (date & time)...
>>>>
>>>> I've seen this topic covered and have it figured out in the case of
>>>> date only, however can't seem to make it work with time included.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail:
>>>> [hidden email]
>>>> For additional commands, e-mail:
>>>> [hidden email]
>>>>
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> [hidden email]
>> For additional commands, e-mail:
>> [hidden email]
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...