Discussion:
[5.3.6] Saving loop-generated checkbox values between requests
Muhammad Gelbana
2012-12-27 21:37:14 UTC
Permalink
I have a numerous checkboxes generated withing a loop that is even inside
another loop

Loop
Loop
Checkbox

So I set the checkbox's value this way:

<t:checkbox t:value="ipSelection(device.ip).selected"/>


So the "ipSelection" method accepts an ip, looks up a map of objects that
have a "selected" boolean property. Now the "device" property isn't
persisted among requests so an exception occurs while submitting the form.

I'm only trying to persist state of selected checkboxes among requests. And
I'm confused why solution doesn't work, and after giving it a little
thought, I'm not sure why should it work !
I implemented a similar approach but that had a static text as the provided
parameter (i.e. method('myKey'))
Lance Java
2012-12-28 08:38:45 UTC
Permalink
The Loop component has a "formState" parameter which defaults to
LoopFormState.VALUES. This means that by default, the Loop component
serializes the loop values into a hidden field in your form. The values are
then reconstructed serverside when the form is posted.

http://tapestry.apache.org/5.3.6/apidocs/org/apache/tapestry5/corelib/components/Loop.html
http://tapestry.apache.org/5.3.6/apidocs/org/apache/tapestry5/corelib/LoopFormState.html

Can you provide a bit more code? In particular, how "ipSelection" and
"device" are constructed / persisted?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Saving-loop-generated-checkbox-values-between-requests-tp5719034p5719038.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org
Muhammad Gelbana
2012-12-28 09:29:54 UTC
Permalink
Thanks a lot ! It's coming along now. I first faced a problem with the loop
state so I disabled it (i.e. NONE) but after you pointed out the javadoc, I
tried the "ITERATION" option that keeps info sufficient info for iterating
over the values only and its working now.

The thing is that "VALUES" serializes the "device" object using toString
and even as its a waste of time to deserialize that. that's not what I
need, I only need a string property acquired from it (IP).

Thanks again :)
Post by Lance Java
The Loop component has a "formState" parameter which defaults to
LoopFormState.VALUES. This means that by default, the Loop component
serializes the loop values into a hidden field in your form. The values are
then reconstructed serverside when the form is posted.
http://tapestry.apache.org/5.3.6/apidocs/org/apache/tapestry5/corelib/components/Loop.html
http://tapestry.apache.org/5.3.6/apidocs/org/apache/tapestry5/corelib/LoopFormState.html
Can you provide a bit more code? In particular, how "ipSelection" and
"device" are constructed / persisted?
--
http://tapestry.1045711.n5.nabble.com/5-3-6-Saving-loop-generated-checkbox-values-between-requests-tp5719034p5719038.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
Lance Java
2012-12-28 09:36:08 UTC
Permalink
Post by Muhammad Gelbana
The thing is that "VALUES" serializes the "device" object using toString
That's not entirely true. Tapestry uses a ValueEncoder to serialize /
deserialize your values. If you don't provide an "encoder" parameter to the
loop, it will use the ValueEncoderSource to find on which is ultimately
backed by the TypeCoercer.

http://tapestry.apache.org/type-coercion.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Saving-loop-generated-checkbox-values-between-requests-tp5719034p5719041.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org
Lance Java
2012-12-28 10:30:05 UTC
Permalink
The problem with ITERATION is that you need to lookup the values when the
form is posted. If these came from a database there is a chance that the
list has changed between rendering the form and posting the form.

I suggest that you either pass an "encoder" parameter to the loop or you
contribute to the ValueEncoderSource or TypeCoercer.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/5-3-6-Saving-loop-generated-checkbox-values-between-requests-tp5719034p5719042.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tapestry.apache.org
For additional commands, e-mail: users-***@tapestry.apache.org
Muhammad Gelbana
2012-12-28 21:07:37 UTC
Permalink
You are correct, I'll have to lookup the whole objects from the database
again and providing a value encoder sounds like the most seamless approach.
Thanks a lot for your help :)
Post by Lance Java
The problem with ITERATION is that you need to lookup the values when the
form is posted. If these came from a database there is a chance that the
list has changed between rendering the form and posting the form.
I suggest that you either pass an "encoder" parameter to the loop or you
contribute to the ValueEncoderSource or TypeCoercer.
--
http://tapestry.1045711.n5.nabble.com/5-3-6-Saving-loop-generated-checkbox-values-between-requests-tp5719034p5719042.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
Loading...