You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Joshua Jackson <jo...@gmail.com> on 2007/08/30 11:51:27 UTC

T5: Binding Date type

Dear all,

Currently I have a field with java.util.Date type in my page, but it
seems that the java.util.Date type is not yet supported in Tapestry5.

This is the exception that I get:
org.apache.tapestry.ioc.internal.util.TapestryException
No adapter from type java.util.Date to type
org.apache.tapestry.Translator is available (registered types are
java.lang.Double, java.lang.Integer, java.lang.Long,
java.lang.String).

What is the workaround if I wanted to have java.util.Date field? While
waiting for these feature to be added on the next release.

Thanks in advance

-- 
It's not just about coding, it's a matter of fulfilling your core being

YM!: thejavafreak
Blog: http://joshuajava.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Binding Date type

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Look at the other translators in:
tapestry-core\src\main\java\org\apache\tapestry\translator

Cheers,
Nick.


Marcelo lotif wrote:
> Nick, can you tell me what Message class is this? What dependence should i
> add?
> I search on maven and there are too much dependencies to add and i can't
> figure out which to use.
> 
> Thanks!
> 
> 2007/8/30, Nick Westgate <ni...@key-planning.co.jp>:
>> Google is your friend. ;-)
>>
>> http://www.google.com/search?source=ig&hl=en&q=DateUtils&btnG=Google+Search
>>
>> Add this to your pom.xml:
>> <dependency>
>>      <groupId>commons-lang</groupId>
>>      <artifactId>commons-lang</artifactId>
>>      <version>2.3</version>
>> </dependency>
>>
>> Hopefully the type coercion systems will simplified to avoid this stuff.
>>
>> Cheers,
>> Nick.
>>
>>
>> Joshua Jackson wrote:
>>> Thanks Nick,
>>>
>>> Can I also get the content of DateUtils.
>>> And which ParseException do I use?
>>>
>>> Thanks in advance
>>>
>>> On 8/30/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
>>>> Add something like the following (tweak the date formats) to your
>> AppModule.java:
>>> ....
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Binding Date type

Posted by Marcelo lotif <ml...@gmail.com>.
Nick, can you tell me what Message class is this? What dependence should i
add?
I search on maven and there are too much dependencies to add and i can't
figure out which to use.

Thanks!

2007/8/30, Nick Westgate <ni...@key-planning.co.jp>:
>
> Google is your friend. ;-)
>
> http://www.google.com/search?source=ig&hl=en&q=DateUtils&btnG=Google+Search
>
> Add this to your pom.xml:
> <dependency>
>      <groupId>commons-lang</groupId>
>      <artifactId>commons-lang</artifactId>
>      <version>2.3</version>
> </dependency>
>
> Hopefully the type coercion systems will simplified to avoid this stuff.
>
> Cheers,
> Nick.
>
>
> Joshua Jackson wrote:
> > Thanks Nick,
> >
> > Can I also get the content of DateUtils.
> > And which ParseException do I use?
> >
> > Thanks in advance
> >
> > On 8/30/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
> >> Add something like the following (tweak the date formats) to your
> AppModule.java:
> >
> > ....
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Atenciosamente,
Marcelo Lotif

Re: T5: Binding Date type

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Google is your friend. ;-)
http://www.google.com/search?source=ig&hl=en&q=DateUtils&btnG=Google+Search

Add this to your pom.xml:
<dependency>
     <groupId>commons-lang</groupId>
     <artifactId>commons-lang</artifactId>
     <version>2.3</version>
</dependency>

Hopefully the type coercion systems will simplified to avoid this stuff.

Cheers,
Nick.


Joshua Jackson wrote:
> Thanks Nick,
> 
> Can I also get the content of DateUtils.
> And which ParseException do I use?
> 
> Thanks in advance
> 
> On 8/30/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
>> Add something like the following (tweak the date formats) to your AppModule.java:
> 
> ....
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Binding Date type

Posted by Joshua Jackson <jo...@gmail.com>.
Thanks Nick,

Can I also get the content of DateUtils.
And which ParseException do I use?

Thanks in advance

On 8/30/07, Nick Westgate <ni...@key-planning.co.jp> wrote:
> Add something like the following (tweak the date formats) to your AppModule.java:

....

-- 
It's not just about coding, it's a matter of fulfilling your core being

YM!: thejavafreak
Blog: http://joshuajava.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: Binding Date type

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Add something like the following (tweak the date formats) to your AppModule.java:

     public static void contributeTranslatorDefaultSource(
         MappedConfiguration<Class<?>, Translator<?>> configuration)
     {
         configuration.add(Date.class, new Translator<Date>()
         {
             /**
              * Parses blank values to null, otherwise parses the client value to a date
              *
              * @throws ValidationException if the clientValue can not be parsed
              */
             public Date parseClient(String clientValue, Messages messages)
                 throws ValidationException
             {
                 if (InternalUtils.isBlank(clientValue))
                     return null;

                 try
                 {
                     String input = clientValue.trim();
                     return DateUtils.parseDate(input, new String[]{"yyyy/MM/dd", "yyyy.MM.dd",
                         "yyyy-MM-dd"});
                 }
                 catch (ParseException e)
                 {
                     throw new ValidationException(messages.format("date-format-exception",
                         clientValue));
                 }
             }

             /**
              * Converts null to an empty string, non-null to a string representation.
              */
             public String toClient(Date value)
             {
                 return value == null ? "" : value.toString();
             }
         });
     }

Cheers,
Nick.


Joshua Jackson wrote:
> Dear all,
> 
> Currently I have a field with java.util.Date type in my page, but it
> seems that the java.util.Date type is not yet supported in Tapestry5.
> 
> This is the exception that I get:
> org.apache.tapestry.ioc.internal.util.TapestryException
> No adapter from type java.util.Date to type
> org.apache.tapestry.Translator is available (registered types are
> java.lang.Double, java.lang.Integer, java.lang.Long,
> java.lang.String).
> 
> What is the workaround if I wanted to have java.util.Date field? While
> waiting for these feature to be added on the next release.
> 
> Thanks in advance
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org