You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by dwi ardi irawan <pe...@gmail.com> on 2009/03/15 20:22:54 UTC

Q : Could not find a coercion from type java.lang.String to type java.util.Date

hi, could anyone help me....

here's my code

....
@Persist("flash")
@Property
private Date twawal, twakhir;
.....

public Link getDailyChart(){
        System.out.println(twawal); // OK
        System.out.println(twakhir); // OK
        return _resources.createEventLink("chart", new Object[]{"400","400",
twawal, twakhir});
    }

    public StreamResponse onChart(final int width, final int height, final
Date _twawal, final Date _twakhir){

        return new StreamResponse(){
            public String getContentType(){
                return "image/gif";
            }
            public InputStream getStream() throws IOException {
                BufferedImage image  =
generateDailyChart().createBufferedImage(width, height);
                ByteArrayOutputStream byteArray = new
ByteArrayOutputStream() ;
                ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
                return new ByteArrayInputStream(byteArray.toByteArray());
            }
            public void prepareResponse(Response response){}
        };
    }

....


i got an error said :
"Could not find a coercion from type java.lang.String to type
java.util.Date.  Available coercions: Double --> Float, Float --> Double,
Long --> Boolean, Long --> Byte, Long --> Double, Long --> Integer, Long -->
Short, Number --> Long, Object --> Object[], Object --> String, Object -->
java.util.List, Object[] --> java.util.List, String --> Boolean, String -->
Double, String --> Long, String --> java.io.File, String -->
java.math.BigDecimal, String --> java.math.BigInteger, String -->
java.text.DateFormat"

can anyone help me ?


-- 
http://www.dwiardiirawan.com
"cos everyone could be extraordinary...lighten up !"

Re: Q : Could not find a coercion from type java.lang.String to type java.util.Date

Posted by dwi ardi irawan <pe...@gmail.com>.
It works, Thnx you


-- 
http://www.dwiardiirawan.com
"cos everyone could be extraordinary...lighten up !"

Re: Q : Could not find a coercion from type java.lang.String to type java.util.Date

Posted by Fernando Padilla <fe...@alum.mit.edu>.
Though I agree that String<->Date by default is a no-go.  I think 
tapestry could have a Long<->Date coercion. :)


Howard Lewis Ship wrote:
> Converting between strings and dates is too finicky for Tapestry to
> handle automatically (without screwing it up for some people).
> 
> Instead of including the Dates as event context values,, try
> converting them to long values (seconds since "the epoch") and then
> convert them back to usable Dates inside your event handler method.
> 
> On Sun, Mar 15, 2009 at 12:22 PM, dwi ardi irawan
> <pe...@gmail.com> wrote:
>> hi, could anyone help me....
>>
>> here's my code
>>
>> ....
>> @Persist("flash")
>> @Property
>> private Date twawal, twakhir;
>> .....
>>
>> public Link getDailyChart(){
>>        System.out.println(twawal); // OK
>>        System.out.println(twakhir); // OK
>>        return _resources.createEventLink("chart", new Object[]{"400","400",
>> twawal, twakhir});
>>    }
>>
>>    public StreamResponse onChart(final int width, final int height, final
>> Date _twawal, final Date _twakhir){
>>
>>        return new StreamResponse(){
>>            public String getContentType(){
>>                return "image/gif";
>>            }
>>            public InputStream getStream() throws IOException {
>>                BufferedImage image  =
>> generateDailyChart().createBufferedImage(width, height);
>>                ByteArrayOutputStream byteArray = new
>> ByteArrayOutputStream() ;
>>                ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
>>                return new ByteArrayInputStream(byteArray.toByteArray());
>>            }
>>            public void prepareResponse(Response response){}
>>        };
>>    }
>>
>> ....
>>
>>
>> i got an error said :
>> "Could not find a coercion from type java.lang.String to type
>> java.util.Date.  Available coercions: Double --> Float, Float --> Double,
>> Long --> Boolean, Long --> Byte, Long --> Double, Long --> Integer, Long -->
>> Short, Number --> Long, Object --> Object[], Object --> String, Object -->
>> java.util.List, Object[] --> java.util.List, String --> Boolean, String -->
>> Double, String --> Long, String --> java.io.File, String -->
>> java.math.BigDecimal, String --> java.math.BigInteger, String -->
>> java.text.DateFormat"
>>
>> can anyone help me ?
>>
>>
>> --
>> http://www.dwiardiirawan.com
>> "cos everyone could be extraordinary...lighten up !"
>>
> 
> 
> 

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


Re: Q : Could not find a coercion from type java.lang.String to type java.util.Date

Posted by Howard Lewis Ship <hl...@gmail.com>.
Converting between strings and dates is too finicky for Tapestry to
handle automatically (without screwing it up for some people).

Instead of including the Dates as event context values,, try
converting them to long values (seconds since "the epoch") and then
convert them back to usable Dates inside your event handler method.

On Sun, Mar 15, 2009 at 12:22 PM, dwi ardi irawan
<pe...@gmail.com> wrote:
> hi, could anyone help me....
>
> here's my code
>
> ....
> @Persist("flash")
> @Property
> private Date twawal, twakhir;
> .....
>
> public Link getDailyChart(){
>        System.out.println(twawal); // OK
>        System.out.println(twakhir); // OK
>        return _resources.createEventLink("chart", new Object[]{"400","400",
> twawal, twakhir});
>    }
>
>    public StreamResponse onChart(final int width, final int height, final
> Date _twawal, final Date _twakhir){
>
>        return new StreamResponse(){
>            public String getContentType(){
>                return "image/gif";
>            }
>            public InputStream getStream() throws IOException {
>                BufferedImage image  =
> generateDailyChart().createBufferedImage(width, height);
>                ByteArrayOutputStream byteArray = new
> ByteArrayOutputStream() ;
>                ChartUtilities.writeBufferedImageAsPNG(byteArray, image) ;
>                return new ByteArrayInputStream(byteArray.toByteArray());
>            }
>            public void prepareResponse(Response response){}
>        };
>    }
>
> ....
>
>
> i got an error said :
> "Could not find a coercion from type java.lang.String to type
> java.util.Date.  Available coercions: Double --> Float, Float --> Double,
> Long --> Boolean, Long --> Byte, Long --> Double, Long --> Integer, Long -->
> Short, Number --> Long, Object --> Object[], Object --> String, Object -->
> java.util.List, Object[] --> java.util.List, String --> Boolean, String -->
> Double, String --> Long, String --> java.io.File, String -->
> java.math.BigDecimal, String --> java.math.BigInteger, String -->
> java.text.DateFormat"
>
> can anyone help me ?
>
>
> --
> http://www.dwiardiirawan.com
> "cos everyone could be extraordinary...lighten up !"
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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