You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2014/10/24 17:02:02 UTC
Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Hi Guys, I have a form contained within a zone where I'm passing an object
into the context value. When I submit the form I get the following
exception.
*parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException: Could
not find a coercion from type java.lang.String to type
org.tapdemo.demo.entity.TimeSheet.*
.tml
<t:zone t:id="formZone" id="formZone">
<t:form t:id="form" zone="formZone" context="ts">
<t:submit t:event="save" context="action.notification"/>
java class
public enum Action {
WARNING, NOTIFICATION, CERTIFICATION
}
@Property
private TimeSheetEntity ts;
public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
this.ts = ts;
}
public void onSave(Action action) {
this.action = action;
}
Aren't you able to pass an object into context? Any ideas what might be
happening here?
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
RE: Could not find a coercion from type java.lang.String to type
org.tapdemo.demo.entity.TimeSheet
Posted by Name Surname <wi...@outlook.com>.
What you can do is to make @Persist(PersistanceConstants.CLIENT) and retrieve only id of the object ( not object, because it may go to broken reference ) of the object between AJAX calls. With that id pass values of that object between calls. It's much safer and consumes less server resources than @SessionState.
> Date: Fri, 24 Oct 2014 11:50:04 -0400
> Subject: Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
> From: gchristman@cardaddy.com
> To: users@tapestry.apache.org
>
> I'm facing a problem where the object hasn't yet been committed to the db
> and there for the object has no id. This is probably the root of this
> exception.
>
> I'm trying to build an ajax wizard where each step has it's own ajax form
> and the db commit will be handled at the end. I was hoping to just pass in
> the value form form A into the context of form B, but that may not be
> possible without an id.
>
> I suppose I could use @SessionState or in the past I've copied the form
> data from form a to form b and sent the original form data out of view, but
> I've been hoping to come up with a better solution than those two since
> processing form A data requires a lot of system resources.
>
> On Fri, Oct 24, 2014 at 11:35 AM, Chris Poulsen <ma...@nesluop.dk>
> wrote:
>
> > Pass the object key as a simple type (string/long) and setup the object in
> > the PREPARE_FOR_SUBMIT handler.
> >
> >
> >
> > On Fri, Oct 24, 2014 at 5:22 PM, George Christman <gchristman@cardaddy.com
> > >
> > wrote:
> >
> > > Unfortunately the valueencoder is not an option for the form component.
> > >
> > > On Fri, Oct 24, 2014 at 11:09 AM, Name Surname <
> > wintertime0101@outlook.com
> > > >
> > > wrote:
> > >
> > > > Hey George. I had a very similar situation. What you can do here is to
> > > > make a new Encoder and put it into appropriate field. Take a look at my
> > > > example.
> > > >
> > > > private class DateEncoder implements ValueEncoder<Date> {
> > > >
> > > > @Override
> > > > public String toClient(Date date) {
> > > > long timeMillis = date.getTime();
> > > > return Long.toString(timeMillis);
> > > > }
> > > >
> > > > @Override
> > > > public Date toValue(String timeMillisAsString) {
> > > > long timeMillis = Long.parseLong(timeMillisAsString);
> > > > Date date = new Date(timeMillis);
> > > > return date;
> > > > }
> > > >
> > > > }
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > and I put into a grid( in your case it will be
> > grid )
> > > > encoder value, something like encoder="dateEncoder". This should work
> > > just
> > > > fine for your case.
> > > >
> > > >
> > > > > Date: Fri, 24 Oct 2014 11:02:02 -0400
> > > > > Subject: Could not find a coercion from type java.lang.String to type
> > > > org.tapdemo.demo.entity.TimeSheet
> > > > > From: gchristman@cardaddy.com
> > > > > To: users@tapestry.apache.org
> > > > >
> > > > > Hi Guys, I have a form contained within a zone where I'm passing an
> > > > object
> > > > > into the context value. When I submit the form I get the following
> > > > > exception.
> > > > >
> > > > > *parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException:
> > > Could
> > > > > not find a coercion from type java.lang.String to type
> > > > > org.tapdemo.demo.entity.TimeSheet.*
> > > > >
> > > > > .tml
> > > > >
> > > > > <t:zone t:id="formZone" id="formZone">
> > > > > <t:form t:id="form" zone="formZone" context="ts">
> > > > >
> > > > > <t:submit t:event="save" context="action.notification"/>
> > > > >
> > > > > java class
> > > > >
> > > > > public enum Action {
> > > > > WARNING, NOTIFICATION, CERTIFICATION
> > > > > }
> > > > >
> > > > > @Property
> > > > > private TimeSheetEntity ts;
> > > > >
> > > > > public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
> > > > > this.ts = ts;
> > > > > }
> > > > >
> > > > > public void onSave(Action action) {
> > > > > this.action = action;
> > > > > }
> > > > >
> > > > > Aren't you able to pass an object into context? Any ideas what might
> > be
> > > > > happening here?
> > > > >
> > > > > --
> > > > > George Christman
> > > > > www.CarDaddy.com
> > > > > P.O. Box 735
> > > > > Johnstown, New York
> > > >
> > > >
> > >
> > >
> > >
> > > --
> > > George Christman
> > > www.CarDaddy.com
> > > P.O. Box 735
> > > Johnstown, New York
> > >
> >
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by Kalle Korhonen <ka...@gmail.com>.
I agree with Lance, but I just want to comment on the overall problem.
Unless the per-step lifetime in your wizard is in the order of a few
seconds, you are, in my opinion, unnecessarily optimizing to reduce
database operations (and if it was in the order a few seconds, a wizard
might not be the right UI flow). Just writing the state of a logical
incomplete operation to the database has lots of benefits, like increased
reliability and trackability. It's likely that only a few percents of your
users are inputting data (i.e. causing write operations) compared to the
number of causing read operations, so any modern database backend is likely
to be able to cope with the load without a hitch.
Just my two cents,
Kalle
On Fri, Oct 24, 2014 at 9:02 AM, Lance Java <la...@googlemail.com>
wrote:
> Instead of null ids, you could give your unsaved entities unique ids that
> are negative. This would require a smart enough ValueEncoder that would NOT
> attempt to lookup negative ids from the database.
>
> It's all sounding a bit hack so you might prefer to pass around a wrapper
> object which knows if the object has been persisted yet or not. Perhaps an
> entity that has been persisted might encode as "P:123" and a new entity not
> yet persisted would encode as "N:123".
>
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by George Christman <gc...@cardaddy.com>.
I think I'm just going to save the values to the db, however for future
knowledge how do i use a value encoder with a form?
On Oct 24, 2014 3:15 PM, "Thiago H de Paula Figueiredo" <th...@gmail.com>
wrote:
> Implementing your own ValueEncoder and contribute it to ValueEncoderSource
> should be enough to get this working.
>
> On Fri, 24 Oct 2014 16:33:52 -0200, Lance Java <la...@googlemail.com>
> wrote:
>
> I'm not sure I fully understand the problem. I thought the form contained
>> all the data so all you needed was a new object to populate.
>>
>> If not, Kalle's suggestion of saving temp state to the db sounds OK to me.
>> Perhaps with a scheduled task to clear out incomplete wizards after some
>> period of inactivity. Good for marketing situations where you can send an
>> email suggesting users complete the wizard.
>>
>> If you want to maintain a stateless wizard, you could use a ValueEncoder
>> which puts all values in the encoded clientside string (eg json or
>> similar).
>> On 24 Oct 2014 17:27, "George Christman" <gc...@cardaddy.com> wrote:
>>
>> Lance, even if I were to give the object a temp id or put it in a wrapper
>>> object, wouldn't that value be lost as soon as the zone finishes
>>> rendering?
>>> It seems to me as if I have three choices, session, commit, or copy form
>>> data from form a to b. Your thoughts?
>>>
>>> On Fri, Oct 24, 2014 at 12:02 PM, Lance Java <la...@googlemail.com>
>>> wrote:
>>>
>>> > Instead of null ids, you could give your unsaved entities unique ids
>>> that
>>> > are negative. This would require a smart enough ValueEncoder that would
>>> NOT
>>> > attempt to lookup negative ids from the database.
>>> >
>>> > It's all sounding a bit hack so you might prefer to pass around a
>>> wrapper
>>> > object which knows if the object has been persisted yet or not. Perhaps
>>> an
>>> > entity that has been persisted might encode as "P:123" and a new entity
>>> not
>>> > yet persisted would encode as "N:123".
>>> >
>>>
>>>
>>>
>>> --
>>> George Christman
>>> www.CarDaddy.com
>>> P.O. Box 735
>>> Johnstown, New York
>>>
>>>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: Could not find a coercion from type java.lang.String to type
org.tapdemo.demo.entity.TimeSheet
Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Implementing your own ValueEncoder and contribute it to ValueEncoderSource
should be enough to get this working.
On Fri, 24 Oct 2014 16:33:52 -0200, Lance Java <la...@googlemail.com>
wrote:
> I'm not sure I fully understand the problem. I thought the form contained
> all the data so all you needed was a new object to populate.
>
> If not, Kalle's suggestion of saving temp state to the db sounds OK to
> me.
> Perhaps with a scheduled task to clear out incomplete wizards after some
> period of inactivity. Good for marketing situations where you can send an
> email suggesting users complete the wizard.
>
> If you want to maintain a stateless wizard, you could use a ValueEncoder
> which puts all values in the encoded clientside string (eg json or
> similar).
> On 24 Oct 2014 17:27, "George Christman" <gc...@cardaddy.com> wrote:
>
>> Lance, even if I were to give the object a temp id or put it in a
>> wrapper
>> object, wouldn't that value be lost as soon as the zone finishes
>> rendering?
>> It seems to me as if I have three choices, session, commit, or copy form
>> data from form a to b. Your thoughts?
>>
>> On Fri, Oct 24, 2014 at 12:02 PM, Lance Java <la...@googlemail.com>
>> wrote:
>>
>> > Instead of null ids, you could give your unsaved entities unique ids
>> that
>> > are negative. This would require a smart enough ValueEncoder that
>> would
>> NOT
>> > attempt to lookup negative ids from the database.
>> >
>> > It's all sounding a bit hack so you might prefer to pass around a
>> wrapper
>> > object which knows if the object has been persisted yet or not.
>> Perhaps
>> an
>> > entity that has been persisted might encode as "P:123" and a new
>> entity
>> not
>> > yet persisted would encode as "N:123".
>> >
>>
>>
>>
>> --
>> George Christman
>> www.CarDaddy.com
>> P.O. Box 735
>> Johnstown, New York
>>
--
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by Lance Java <la...@googlemail.com>.
I'm not sure I fully understand the problem. I thought the form contained
all the data so all you needed was a new object to populate.
If not, Kalle's suggestion of saving temp state to the db sounds OK to me.
Perhaps with a scheduled task to clear out incomplete wizards after some
period of inactivity. Good for marketing situations where you can send an
email suggesting users complete the wizard.
If you want to maintain a stateless wizard, you could use a ValueEncoder
which puts all values in the encoded clientside string (eg json or
similar).
On 24 Oct 2014 17:27, "George Christman" <gc...@cardaddy.com> wrote:
> Lance, even if I were to give the object a temp id or put it in a wrapper
> object, wouldn't that value be lost as soon as the zone finishes rendering?
> It seems to me as if I have three choices, session, commit, or copy form
> data from form a to b. Your thoughts?
>
> On Fri, Oct 24, 2014 at 12:02 PM, Lance Java <la...@googlemail.com>
> wrote:
>
> > Instead of null ids, you could give your unsaved entities unique ids that
> > are negative. This would require a smart enough ValueEncoder that would
> NOT
> > attempt to lookup negative ids from the database.
> >
> > It's all sounding a bit hack so you might prefer to pass around a wrapper
> > object which knows if the object has been persisted yet or not. Perhaps
> an
> > entity that has been persisted might encode as "P:123" and a new entity
> not
> > yet persisted would encode as "N:123".
> >
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by George Christman <gc...@cardaddy.com>.
Lance, even if I were to give the object a temp id or put it in a wrapper
object, wouldn't that value be lost as soon as the zone finishes rendering?
It seems to me as if I have three choices, session, commit, or copy form
data from form a to b. Your thoughts?
On Fri, Oct 24, 2014 at 12:02 PM, Lance Java <la...@googlemail.com>
wrote:
> Instead of null ids, you could give your unsaved entities unique ids that
> are negative. This would require a smart enough ValueEncoder that would NOT
> attempt to lookup negative ids from the database.
>
> It's all sounding a bit hack so you might prefer to pass around a wrapper
> object which knows if the object has been persisted yet or not. Perhaps an
> entity that has been persisted might encode as "P:123" and a new entity not
> yet persisted would encode as "N:123".
>
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by Lance Java <la...@googlemail.com>.
Instead of null ids, you could give your unsaved entities unique ids that
are negative. This would require a smart enough ValueEncoder that would NOT
attempt to lookup negative ids from the database.
It's all sounding a bit hack so you might prefer to pass around a wrapper
object which knows if the object has been persisted yet or not. Perhaps an
entity that has been persisted might encode as "P:123" and a new entity not
yet persisted would encode as "N:123".
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by George Christman <gc...@cardaddy.com>.
I'm facing a problem where the object hasn't yet been committed to the db
and there for the object has no id. This is probably the root of this
exception.
I'm trying to build an ajax wizard where each step has it's own ajax form
and the db commit will be handled at the end. I was hoping to just pass in
the value form form A into the context of form B, but that may not be
possible without an id.
I suppose I could use @SessionState or in the past I've copied the form
data from form a to form b and sent the original form data out of view, but
I've been hoping to come up with a better solution than those two since
processing form A data requires a lot of system resources.
On Fri, Oct 24, 2014 at 11:35 AM, Chris Poulsen <ma...@nesluop.dk>
wrote:
> Pass the object key as a simple type (string/long) and setup the object in
> the PREPARE_FOR_SUBMIT handler.
>
>
>
> On Fri, Oct 24, 2014 at 5:22 PM, George Christman <gchristman@cardaddy.com
> >
> wrote:
>
> > Unfortunately the valueencoder is not an option for the form component.
> >
> > On Fri, Oct 24, 2014 at 11:09 AM, Name Surname <
> wintertime0101@outlook.com
> > >
> > wrote:
> >
> > > Hey George. I had a very similar situation. What you can do here is to
> > > make a new Encoder and put it into appropriate field. Take a look at my
> > > example.
> > >
> > > private class DateEncoder implements ValueEncoder<Date> {
> > >
> > > @Override
> > > public String toClient(Date date) {
> > > long timeMillis = date.getTime();
> > > return Long.toString(timeMillis);
> > > }
> > >
> > > @Override
> > > public Date toValue(String timeMillisAsString) {
> > > long timeMillis = Long.parseLong(timeMillisAsString);
> > > Date date = new Date(timeMillis);
> > > return date;
> > > }
> > >
> > > }
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > and I put into a grid( in your case it will be
> grid )
> > > encoder value, something like encoder="dateEncoder". This should work
> > just
> > > fine for your case.
> > >
> > >
> > > > Date: Fri, 24 Oct 2014 11:02:02 -0400
> > > > Subject: Could not find a coercion from type java.lang.String to type
> > > org.tapdemo.demo.entity.TimeSheet
> > > > From: gchristman@cardaddy.com
> > > > To: users@tapestry.apache.org
> > > >
> > > > Hi Guys, I have a form contained within a zone where I'm passing an
> > > object
> > > > into the context value. When I submit the form I get the following
> > > > exception.
> > > >
> > > > *parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException:
> > Could
> > > > not find a coercion from type java.lang.String to type
> > > > org.tapdemo.demo.entity.TimeSheet.*
> > > >
> > > > .tml
> > > >
> > > > <t:zone t:id="formZone" id="formZone">
> > > > <t:form t:id="form" zone="formZone" context="ts">
> > > >
> > > > <t:submit t:event="save" context="action.notification"/>
> > > >
> > > > java class
> > > >
> > > > public enum Action {
> > > > WARNING, NOTIFICATION, CERTIFICATION
> > > > }
> > > >
> > > > @Property
> > > > private TimeSheetEntity ts;
> > > >
> > > > public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
> > > > this.ts = ts;
> > > > }
> > > >
> > > > public void onSave(Action action) {
> > > > this.action = action;
> > > > }
> > > >
> > > > Aren't you able to pass an object into context? Any ideas what might
> be
> > > > happening here?
> > > >
> > > > --
> > > > George Christman
> > > > www.CarDaddy.com
> > > > P.O. Box 735
> > > > Johnstown, New York
> > >
> > >
> >
> >
> >
> > --
> > George Christman
> > www.CarDaddy.com
> > P.O. Box 735
> > Johnstown, New York
> >
>
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by Chris Poulsen <ma...@nesluop.dk>.
Pass the object key as a simple type (string/long) and setup the object in
the PREPARE_FOR_SUBMIT handler.
On Fri, Oct 24, 2014 at 5:22 PM, George Christman <gc...@cardaddy.com>
wrote:
> Unfortunately the valueencoder is not an option for the form component.
>
> On Fri, Oct 24, 2014 at 11:09 AM, Name Surname <wintertime0101@outlook.com
> >
> wrote:
>
> > Hey George. I had a very similar situation. What you can do here is to
> > make a new Encoder and put it into appropriate field. Take a look at my
> > example.
> >
> > private class DateEncoder implements ValueEncoder<Date> {
> >
> > @Override
> > public String toClient(Date date) {
> > long timeMillis = date.getTime();
> > return Long.toString(timeMillis);
> > }
> >
> > @Override
> > public Date toValue(String timeMillisAsString) {
> > long timeMillis = Long.parseLong(timeMillisAsString);
> > Date date = new Date(timeMillis);
> > return date;
> > }
> >
> > }
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > and I put into a grid( in your case it will be grid )
> > encoder value, something like encoder="dateEncoder". This should work
> just
> > fine for your case.
> >
> >
> > > Date: Fri, 24 Oct 2014 11:02:02 -0400
> > > Subject: Could not find a coercion from type java.lang.String to type
> > org.tapdemo.demo.entity.TimeSheet
> > > From: gchristman@cardaddy.com
> > > To: users@tapestry.apache.org
> > >
> > > Hi Guys, I have a form contained within a zone where I'm passing an
> > object
> > > into the context value. When I submit the form I get the following
> > > exception.
> > >
> > > *parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException:
> Could
> > > not find a coercion from type java.lang.String to type
> > > org.tapdemo.demo.entity.TimeSheet.*
> > >
> > > .tml
> > >
> > > <t:zone t:id="formZone" id="formZone">
> > > <t:form t:id="form" zone="formZone" context="ts">
> > >
> > > <t:submit t:event="save" context="action.notification"/>
> > >
> > > java class
> > >
> > > public enum Action {
> > > WARNING, NOTIFICATION, CERTIFICATION
> > > }
> > >
> > > @Property
> > > private TimeSheetEntity ts;
> > >
> > > public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
> > > this.ts = ts;
> > > }
> > >
> > > public void onSave(Action action) {
> > > this.action = action;
> > > }
> > >
> > > Aren't you able to pass an object into context? Any ideas what might be
> > > happening here?
> > >
> > > --
> > > George Christman
> > > www.CarDaddy.com
> > > P.O. Box 735
> > > Johnstown, New York
> >
> >
>
>
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York
>
Re: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
Posted by George Christman <gc...@cardaddy.com>.
Unfortunately the valueencoder is not an option for the form component.
On Fri, Oct 24, 2014 at 11:09 AM, Name Surname <wi...@outlook.com>
wrote:
> Hey George. I had a very similar situation. What you can do here is to
> make a new Encoder and put it into appropriate field. Take a look at my
> example.
>
> private class DateEncoder implements ValueEncoder<Date> {
>
> @Override
> public String toClient(Date date) {
> long timeMillis = date.getTime();
> return Long.toString(timeMillis);
> }
>
> @Override
> public Date toValue(String timeMillisAsString) {
> long timeMillis = Long.parseLong(timeMillisAsString);
> Date date = new Date(timeMillis);
> return date;
> }
>
> }
>
>
>
>
>
>
>
>
>
>
>
>
> and I put into a grid( in your case it will be grid )
> encoder value, something like encoder="dateEncoder". This should work just
> fine for your case.
>
>
> > Date: Fri, 24 Oct 2014 11:02:02 -0400
> > Subject: Could not find a coercion from type java.lang.String to type
> org.tapdemo.demo.entity.TimeSheet
> > From: gchristman@cardaddy.com
> > To: users@tapestry.apache.org
> >
> > Hi Guys, I have a form contained within a zone where I'm passing an
> object
> > into the context value. When I submit the form I get the following
> > exception.
> >
> > *parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException: Could
> > not find a coercion from type java.lang.String to type
> > org.tapdemo.demo.entity.TimeSheet.*
> >
> > .tml
> >
> > <t:zone t:id="formZone" id="formZone">
> > <t:form t:id="form" zone="formZone" context="ts">
> >
> > <t:submit t:event="save" context="action.notification"/>
> >
> > java class
> >
> > public enum Action {
> > WARNING, NOTIFICATION, CERTIFICATION
> > }
> >
> > @Property
> > private TimeSheetEntity ts;
> >
> > public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
> > this.ts = ts;
> > }
> >
> > public void onSave(Action action) {
> > this.action = action;
> > }
> >
> > Aren't you able to pass an object into context? Any ideas what might be
> > happening here?
> >
> > --
> > George Christman
> > www.CarDaddy.com
> > P.O. Box 735
> > Johnstown, New York
>
>
--
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York
RE: Could not find a coercion from type java.lang.String to type
org.tapdemo.demo.entity.TimeSheet
Posted by Name Surname <wi...@outlook.com>.
Hey George. I had a very similar situation. What you can do here is to make a new Encoder and put it into appropriate field. Take a look at my example.
private class DateEncoder implements ValueEncoder<Date> {
@Override
public String toClient(Date date) {
long timeMillis = date.getTime();
return Long.toString(timeMillis);
}
@Override
public Date toValue(String timeMillisAsString) {
long timeMillis = Long.parseLong(timeMillisAsString);
Date date = new Date(timeMillis);
return date;
}
}
and I put into a grid( in your case it will be grid ) encoder value, something like encoder="dateEncoder". This should work just fine for your case.
> Date: Fri, 24 Oct 2014 11:02:02 -0400
> Subject: Could not find a coercion from type java.lang.String to type org.tapdemo.demo.entity.TimeSheet
> From: gchristman@cardaddy.com
> To: users@tapestry.apache.org
>
> Hi Guys, I have a form contained within a zone where I'm passing an object
> into the context value. When I submit the form I get the following
> exception.
>
> *parameter #1: org.apache.tapestry5.ioc.util.UnknownValueException: Could
> not find a coercion from type java.lang.String to type
> org.tapdemo.demo.entity.TimeSheet.*
>
> .tml
>
> <t:zone t:id="formZone" id="formZone">
> <t:form t:id="form" zone="formZone" context="ts">
>
> <t:submit t:event="save" context="action.notification"/>
>
> java class
>
> public enum Action {
> WARNING, NOTIFICATION, CERTIFICATION
> }
>
> @Property
> private TimeSheetEntity ts;
>
> public void onPrepareForSubmitFromForm(TimeSheetEntity ts) {
> this.ts = ts;
> }
>
> public void onSave(Action action) {
> this.action = action;
> }
>
> Aren't you able to pass an object into context? Any ideas what might be
> happening here?
>
> --
> George Christman
> www.CarDaddy.com
> P.O. Box 735
> Johnstown, New York