[T5] Loops in a Form with child components

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[T5] Loops in a Form with child components

Adriaan Joubert-3
Hi,

I've got the following problem: I have a list of relatively complex
data objects that I need to edit, which leads to the following form:

        <t:form t:id="cform">
                <t:submit value="Save"/>
                <t:loop source="constraints" value="constraint" encoder="constraintEncoder">
                        <t:myconstraint constraint="constraint" />
                </t:loop>
        </t:form>

So far so great, but I'm having real problems with the MyConstraint
class, as the only form event that trickles down is 'validate'. This
creates problem with the initialisation of some data structures, which
I would usually do in onPrepare, and also with the updating of data
structures when saving (onSuccess).

I've managed to work around the initialisation problems by
initialising everything in the getter methods and liberal use of
@Cached (neat, that!). This works, but is different from the way I
initialise other forms.

Saving is a bigger issue, as I need to update some data structures. I
can do this in 'onValidate', but that is just plain wrong.

Am I trying to do something that I should not be doing? Or have I just
overlooked something? Anybody got a pattern for dealing with this type
of thing?

Thanks!

Adriaan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [T5] Loops in a Form with child components

Adriaan Joubert-3
Hi,

thought I'd post my experiences with a form with multiple components in a loop.

My initial (preferred) solution was to have a single form with a
series of components in a loop. As far as I can tell this is simply
not possible with Tapestry at the moment. What can be done is:

1. Inject FormSupport into the components and register a handler. This
can be used to register a handler with storeAndExecute that makes it
possible to do the equivalent of onPrepare.
2. All validation events will bubble up to the component, so you will
get a validation event per form field - not particularly useful I
found.
3. You do not receive any events with which to manipulate the form
data after a submit, so all values need to be written into data
structures that are accessible from the containing page class.
4. The Grid rows class in the tapestry source code is a useful place
to look for FormSupport use.

After spending a lot of time on this I gave up and re-did the page
with every component in its own form. Then all the great T5 form
support kicks in and it is easy to deal with data and state.
Unfortunately this requires the user to save every form separately -
ideally AJAX should take care of that automatically. Unfortunately
there are two separate problems with dealing with zones in a loop (See
https://issues.apache.org/jira/browse/TAPESTRY-2360 and
https://issues.apache.org/jira/browse/TAPESTRY-2324) so it is not
currently possible to use zones.

T5 is fantastic and really easy to use, but this area still seems very
unfinished.

Adriaan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]