You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by m!ga <ga...@gmail.com> on 2009/06/12 17:23:58 UTC
Tapestry 5.1 exception "Could not find a coercion from type ..."
on form submit
Hi everyone. We just started migration from tapestry 5.0 to 5.1 and found a
lot of strange exeptions. Here is one of them.
page class:
public class Test {
@SuppressWarnings({"unused", "UnusedDeclaration"})
@Component(id = "form")
private Form form;
@Property
private SomeClass someClass;
@Property
private SomeClass[] someClasses = {new SomeClass("1"),new
SomeClass("2"),new SomeClass("3"),new SomeClass("4"),new SomeClass("5")};
public class SomeClass
{
private String s = "SomeClass ";
public SomeClass(String s)
{
this.s += s;
}
public String toString()
{
return s;
}
}
}
tml file:
<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
<form t:id="form">
<t:loop source="someClasses" value="someClass">
<div>${someClass}</div>
</t:loop>
<input t:type="submit" value="Push me" />
</form>
</div>
Works fine unless you try to submit form. It throws something like that:
Caused by: java.lang.IllegalArgumentException: Could not find a coercion
from type java.lang.String to type ru.kupivip.pages.shop.Test$SomeClass.
Available coe
rcions: Double --> Float, Float --> Double...bla bla bla...
It can be solved by not-so-good-looking-code like this:
private SomeClass someClass;
public Object getSomeClass()
{
return someClass;
}
public void setSomeClass(Object maybeSomeClass)
{
someClass = maybeSomeClass != null && maybeSomeClass instanceof SomeClass
? (SomeClass) maybeSomeClass : null;
}
I've debugged the setter ant it seems that it is called 2 times:
1st time after onActivate phase
2nd time after onSubmit/onActivate
and 1st time the argument maybeSomeClass is not instance of SomeClass but
its toString() value!
--
View this message in context: http://www.nabble.com/Tapestry-5.1-exception--%22Could-not-find-a-coercion-from-type-...%22-on-form-submit-tp24001080p24001080.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry 5.1 exception "Could not find a coercion from type ..." on form submit
Posted by Robert Zeigler <ro...@scazdl.org>.
Hi,
There was a change from using pkencoder to valueencoder (it's noted in
the upgrade notes) in 5.1 for loops contained in forms.
See: http://tapestry.apache.org/tapestry5.1/upgrade.html
Particularly, the section:
"Release 5.1.0.0
Primary Key Encoder
This is the change between releases that is most likely to affect your
upgrade."
Robert
On Jun 12, 2009, at 6/1210:23 AM , m!ga wrote:
>
> Hi everyone. We just started migration from tapestry 5.0 to 5.1 and
> found a
> lot of strange exeptions. Here is one of them.
>
> page class:
>
> public class Test {
>
> @SuppressWarnings({"unused", "UnusedDeclaration"})
> @Component(id = "form")
> private Form form;
>
> @Property
> private SomeClass someClass;
>
> @Property
> private SomeClass[] someClasses = {new SomeClass("1"),new
> SomeClass("2"),new SomeClass("3"),new SomeClass("4"),new
> SomeClass("5")};
>
>
> public class SomeClass
> {
> private String s = "SomeClass ";
>
> public SomeClass(String s)
> {
> this.s += s;
> }
> public String toString()
> {
> return s;
> }
> }
> }
>
>
> tml file:
>
> <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
>
> <form t:id="form">
> <t:loop source="someClasses" value="someClass">
> <div>${someClass}</div>
> </t:loop>
> <input t:type="submit" value="Push me" />
> </form>
> </div>
>
> Works fine unless you try to submit form. It throws something like
> that:
>
> Caused by: java.lang.IllegalArgumentException: Could not find a
> coercion
> from type java.lang.String to type ru.kupivip.pages.shop.Test
> $SomeClass.
> Available coe
> rcions: Double --> Float, Float --> Double...bla bla bla...
>
> It can be solved by not-so-good-looking-code like this:
>
> private SomeClass someClass;
>
> public Object getSomeClass()
> {
> return someClass;
> }
>
> public void setSomeClass(Object maybeSomeClass)
> {
> someClass = maybeSomeClass != null && maybeSomeClass instanceof
> SomeClass
> ? (SomeClass) maybeSomeClass : null;
> }
>
> I've debugged the setter ant it seems that it is called 2 times:
> 1st time after onActivate phase
> 2nd time after onSubmit/onActivate
>
> and 1st time the argument maybeSomeClass is not instance of
> SomeClass but
> its toString() value!
>
>
> --
> View this message in context: http://www.nabble.com/Tapestry-5.1-exception--%22Could-not-find-a-coercion-from-type-...%22-on-form-submit-tp24001080p24001080.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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