You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chuck Kring <cj...@pacbell.net> on 2009/04/18 19:11:19 UTC

T5.0.18: how to have variable data structures in a bean?

Hi all,

This is somewhat complicated so bear with me.

I'm trying to create a bean with a variable number of fields, each which 
has a name and an associated select box to set various properties.   
The  tml looks something like this:

.....
<tr t: type="AjaxFormLoop" t:sources="residents" t:value="resident" 
t:encoder="encoder">
    <t:submitnotifier>
        <td><input t:type="TextField" t:value="resident.name" ></td>
       <t:loop source="resident.profiles" value="profile">
              <td><select: t:value="profile.selection" 
model="profile.model" encoder="profile.model" /> </td>
       </t:loop>
    </t:submitnotifier>
</tr>

Resident and profile are standard beans except that resident contains an 
ArrayList of profiles that is accesses through getProfiles().

This all works pretty well except that Tapestry 5.0.18 tries to 
serialize the profile bean (I get errors unless I make it extend 
Serializable)  AND it appears to set the selection on another instance 
of the profile bean.  I suspect that tapestry serializes the profile 
bean,  unserializes it to create it's own copy, then changes selection 
on it's own copy.  My bean never sees the updated result.

The work around is ugly - to store the profiles list in the session, the 
retrieve it and update the actual bean in in the profile.setSelection() 
method. 

My question is is this a bug in tapestry or am I doing something wrong?  
Is there a better way to accomplish this?

Thanks!

Chuck Kring





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


Re: T5.0.18: how to have variable data structures in a bean?

Posted by Chuck Kring <cj...@pacbell.net>.
Ville,

It works like a charm.   I appreciate your help.  Thanks.

Chuck


Ville Virtanen wrote:
> Hi,
>
> the given tml is missing encoder for the inner loop. Without this T5 uses
> the default approach which is the highly inefficient
> serialize-whole-thing-to-form-data. 
>
> This encoder can be constructed in the bean itself (resident) but imho
> should not be there, so the best approach (afaik) is to construct it in the
> page based on the data that resident contains (So that one encoder is
> created per resident for the profiles loop.).
>
>  Add the encoder and if this doesn't work attach the associated java code
> snippet also
>
>  - Ville
>
>
> Chuck Kring wrote:
>   
>> Hi all,
>>
>> This is somewhat complicated so bear with me.
>>
>> I'm trying to create a bean with a variable number of fields, each which 
>> has a name and an associated select box to set various properties.   
>> The  tml looks something like this:
>>
>> .....
>> <tr t: type="AjaxFormLoop" t:sources="residents" t:value="resident" 
>> t:encoder="encoder">
>>     <t:submitnotifier>
>>         <td><input t:type="TextField" t:value="resident.name" ></td>
>>        <t:loop source="resident.profiles" value="profile">
>>               <td><select: t:value="profile.selection" 
>> model="profile.model" encoder="profile.model" /> </td>
>>        </t:loop>
>>     </t:submitnotifier>
>> </tr>
>>
>> Resident and profile are standard beans except that resident contains an 
>> ArrayList of profiles that is accesses through getProfiles().
>>
>> This all works pretty well except that Tapestry 5.0.18 tries to 
>> serialize the profile bean (I get errors unless I make it extend 
>> Serializable)  AND it appears to set the selection on another instance 
>> of the profile bean.  I suspect that tapestry serializes the profile 
>> bean,  unserializes it to create it's own copy, then changes selection 
>> on it's own copy.  My bean never sees the updated result.
>>
>> The work around is ugly - to store the profiles list in the session, the 
>> retrieve it and update the actual bean in in the profile.setSelection() 
>> method. 
>>
>> My question is is this a bug in tapestry or am I doing something wrong?  
>> Is there a better way to accomplish this?
>>
>> Thanks!
>>
>> Chuck Kring
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>>
>>     
>
>   

Re: T5.0.18: how to have variable data structures in a bean?

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi,

the given tml is missing encoder for the inner loop. Without this T5 uses
the default approach which is the highly inefficient
serialize-whole-thing-to-form-data. 

This encoder can be constructed in the bean itself (resident) but imho
should not be there, so the best approach (afaik) is to construct it in the
page based on the data that resident contains (So that one encoder is
created per resident for the profiles loop.).

 Add the encoder and if this doesn't work attach the associated java code
snippet also

 - Ville


Chuck Kring wrote:
> 
> Hi all,
> 
> This is somewhat complicated so bear with me.
> 
> I'm trying to create a bean with a variable number of fields, each which 
> has a name and an associated select box to set various properties.   
> The  tml looks something like this:
> 
> .....
> <tr t: type="AjaxFormLoop" t:sources="residents" t:value="resident" 
> t:encoder="encoder">
>     <t:submitnotifier>
>         <td><input t:type="TextField" t:value="resident.name" ></td>
>        <t:loop source="resident.profiles" value="profile">
>               <td><select: t:value="profile.selection" 
> model="profile.model" encoder="profile.model" /> </td>
>        </t:loop>
>     </t:submitnotifier>
> </tr>
> 
> Resident and profile are standard beans except that resident contains an 
> ArrayList of profiles that is accesses through getProfiles().
> 
> This all works pretty well except that Tapestry 5.0.18 tries to 
> serialize the profile bean (I get errors unless I make it extend 
> Serializable)  AND it appears to set the selection on another instance 
> of the profile bean.  I suspect that tapestry serializes the profile 
> bean,  unserializes it to create it's own copy, then changes selection 
> on it's own copy.  My bean never sees the updated result.
> 
> The work around is ugly - to store the profiles list in the session, the 
> retrieve it and update the actual bean in in the profile.setSelection() 
> method. 
> 
> My question is is this a bug in tapestry or am I doing something wrong?  
> Is there a better way to accomplish this?
> 
> Thanks!
> 
> Chuck Kring
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5.0.18%3A-how-to-have-variable-data-structures-in-a-bean--tp23115133p23120688.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