You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Athneria, Mahendra" <ma...@atos.net> on 2012/06/22 07:30:12 UTC

Encoder with

Hi,

I have one Page which is displaying details of some Client. I am using t:loop to display some data. In t: loop I am just passing source and value. So far so good, my page is working fine. But when I try to submit the Page it suddenly give me the Exception.

"Could not find a coercion from type java.lang.String to type [addressUsageValue] Available coercions:.........."

Below is the sample code

<t:loop source="addressUsageInfo" value="addressUsageValue">
                  <tr>
                              <td>${addressUsageValue?.usage}</td>
                              <td>${addressUsageValue?.address}</td>
                              <td>${addressUsageValue?.postCode}</td>
                              <td>${addressUsageValue?.city}</td>
                              <td>${addressUsageValue?.country}</td>
                  </tr>
</t:loop>

I did some goggling and find below references.

http://tapestry.apache.org/5.3.3/apidocs/org/apache/tapestry5/corelib/components/Loop.html
https://issues.apache.org/jira/browse/TAP5-609

So I have created encoder for Loop. Below is the sample code. In below toClient() method I have randomly returned any value and in toValue() method I am returning null.

      private final ValueEncoder<DtoAddressUsageInfo> addressUssageEncoder = new ValueEncoder<DtoAddressUsageInfo>() {

            public String toClient(DtoAddressUsageInfo value) {
                  return String.valueOf(value.getUsage());
            }

            public DtoAddressUsageInfo toValue(String clientValue) {
                  return null;
            }

      };
Now my code is working fine and I am able to submit the form.

Here my doubt comes

First - I am not able to understand why encoder is required when using loop?? And if it is required to submit the form then why it is not Mandatory parameter??

Second - I have just implemented the Encoder without any logic. I am not able to understand where toValue() and toClient() method is used and what is the purpose?

Third - when I submit the Page why form required Encoder??

Regards,
Mahendra Athneria
[cid:221044411@01072011-28AB]
Ext-+91 22 6733 3729
Mob-+91 9833 121 309
mahendra.athneria@atos.net
[cid:image001.gif@01CA57B6.7335F1E0]


RE: Encoder with

Posted by "Athneria, Mahendra" <ma...@atos.net>.
Thanks a lot Thiago. I got the point :)

Regards,
Mahendra Athneria

Ext-+91 22 6733 3729
Mob-+91 9833 121 309
mahendra.athneria@atos.net



-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Friday, June 22, 2012 5:18 PM
To: Tapestry users; dev@tapestry.apache.org; Athneria, Mahendra
Subject: Re: Encoder with <t:loop>


On Fri, 22 Jun 2012 02:30:12 -0300, Athneria, Mahendra  
<ma...@atos.net> wrote:

> Hi,

Hi!

> "Could not find a coercion from type java.lang.String to type  
> [addressUsageValue] Available coercions:.........."

> First - I am not able to understand why encoder is required when using  
> loop??

It's just required when the Loop is inside a Form and the value of the  
Loop's formState parameter is different from LoopFormState.NONE. So you  
don't need to provide a ValueEncoder when you add formState="none" to your  
Loop.

> And if it is required to submit the form then why it is not Mandatory  
> parameter??

It is because Loop is trying to submit values inside it.

> Second - I have just implemented the Encoder without any logic. I am not  
> able to understand where toValue() and toClient() method is used and  
> what is the purpose?

It's used by Loop in order to restore the objects during form submission  
and apply the submitted values to them.

> Third - when I submit the Page why form required Encoder??

Answered above.

-- 
Thiago H. de Paula Figueiredo

RE: Encoder with

Posted by "Athneria, Mahendra" <ma...@atos.net>.
Thanks a lot Thiago. I got the point :)

Regards,
Mahendra Athneria

Ext-+91 22 6733 3729
Mob-+91 9833 121 309
mahendra.athneria@atos.net



-----Original Message-----
From: Thiago H de Paula Figueiredo [mailto:thiagohp@gmail.com] 
Sent: Friday, June 22, 2012 5:18 PM
To: Tapestry users; dev@tapestry.apache.org; Athneria, Mahendra
Subject: Re: Encoder with <t:loop>


On Fri, 22 Jun 2012 02:30:12 -0300, Athneria, Mahendra  
<ma...@atos.net> wrote:

> Hi,

Hi!

> "Could not find a coercion from type java.lang.String to type  
> [addressUsageValue] Available coercions:.........."

> First - I am not able to understand why encoder is required when using  
> loop??

It's just required when the Loop is inside a Form and the value of the  
Loop's formState parameter is different from LoopFormState.NONE. So you  
don't need to provide a ValueEncoder when you add formState="none" to your  
Loop.

> And if it is required to submit the form then why it is not Mandatory  
> parameter??

It is because Loop is trying to submit values inside it.

> Second - I have just implemented the Encoder without any logic. I am not  
> able to understand where toValue() and toClient() method is used and  
> what is the purpose?

It's used by Loop in order to restore the objects during form submission  
and apply the submitted values to them.

> Third - when I submit the Page why form required Encoder??

Answered above.

-- 
Thiago H. de Paula Figueiredo

Re: Encoder with

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 22 Jun 2012 02:30:12 -0300, Athneria, Mahendra  
<ma...@atos.net> wrote:

> Hi,

Hi!

> "Could not find a coercion from type java.lang.String to type  
> [addressUsageValue] Available coercions:.........."

> First - I am not able to understand why encoder is required when using  
> loop??

It's just required when the Loop is inside a Form and the value of the  
Loop's formState parameter is different from LoopFormState.NONE. So you  
don't need to provide a ValueEncoder when you add formState="none" to your  
Loop.

> And if it is required to submit the form then why it is not Mandatory  
> parameter??

It is because Loop is trying to submit values inside it.

> Second - I have just implemented the Encoder without any logic. I am not  
> able to understand where toValue() and toClient() method is used and  
> what is the purpose?

It's used by Loop in order to restore the objects during form submission  
and apply the submitted values to them.

> Third - when I submit the Page why form required Encoder??

Answered above.

-- 
Thiago H. de Paula Figueiredo

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


Re: Encoder with

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 22 Jun 2012 02:30:12 -0300, Athneria, Mahendra  
<ma...@atos.net> wrote:

> Hi,

Hi!

> "Could not find a coercion from type java.lang.String to type  
> [addressUsageValue] Available coercions:.........."

> First - I am not able to understand why encoder is required when using  
> loop??

It's just required when the Loop is inside a Form and the value of the  
Loop's formState parameter is different from LoopFormState.NONE. So you  
don't need to provide a ValueEncoder when you add formState="none" to your  
Loop.

> And if it is required to submit the form then why it is not Mandatory  
> parameter??

It is because Loop is trying to submit values inside it.

> Second - I have just implemented the Encoder without any logic. I am not  
> able to understand where toValue() and toClient() method is used and  
> what is the purpose?

It's used by Loop in order to restore the objects during form submission  
and apply the submitted values to them.

> Third - when I submit the Page why form required Encoder??

Answered above.

-- 
Thiago H. de Paula Figueiredo

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