You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Geoffrey Wiseman <ge...@gmail.com> on 2009/07/24 18:31:02 UTC

Loop & Form

I'm dealing with my first loop-and-form and it's not behaving as I'd hoped,
so I'm looking for some thoughts.
Basically -- I've got a dnyamic number of columns and I want to be able to
define the data type of the column in a header cell using Enums.

So, in essence, I've got an array of null enums, and I want to iterate
across, populate a select for each within a form, submit the values and save
them.

The selects render with the enum values, but when it comes to validation,
the array to which I bound the selects is still an array of nulls, even
though I've changed the selected item in the select box.

These aren't entities, I don't need a primary key encoder -- is this a
problem because I want to replace the value rather than, say, edit the
content of a mutable object?  Thoughts on how to address this properly in
Tapestry?

Thanks

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Fwd: Loop & Form

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 24 Jul 2009 16:49:58 -0300, Geoffrey Wiseman  
<ge...@gmail.com> escreveu:

> Yup - the getters and setters and index seemed to solve the problem for  
> me;

Yes! :)

> I've just verified that I can now do the validation I was hoping to do;  
> that  should be good enough for now.  Thanks for the suggestion.

You're welcome!

> Seems like if that's commonly necessary for loops and forms, there needs  
> to be some kind of enhancement to the Loop docs in the component  
> reference, but at least now there'll be a mailing list reference to it.

+1 to that. Could you post a documentation JIRA?

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Fwd: Loop & Form

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Jul 24, 2009 at 3:39 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Fri, 24 Jul 2009 16:23:20 -0300, Geoffrey Wiseman <
> geoffrey.wiseman@gmail.com> escreveu:
>
>  The processFormSubmission() code seems to be working, so possibly an issue
>> with bindings, loops and arrays?  I don't know enough about the binding code
>> to trace that either.  I'll try this pattern here, although it would be nice
>> if the bound array would work without these methods.
>>
>
> Has the proposed solution worked? I don't think you need to dive into
> binding code here, just put some breakpoints in the get and set methods in
> your page.
>

Yup - the getters and setters and index seemed to solve the problem for me;
I've just verified that I can now do the validation I was hoping to do; that
should be good enough for now.  Thanks for the suggestion.  Seems like if
that's commonly necessary for loops and forms, there needs to be some kind
of enhancement to the Loop docs in the component reference, but at least now
there'll be a mailing list reference to it.

Thanks again,

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Fwd: Loop & Form

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 24 Jul 2009 16:23:20 -0300, Geoffrey Wiseman  
<ge...@gmail.com> escreveu:

> The processFormSubmission() code seems to be working, so possibly an  
> issue with bindings, loops and arrays?  I don't know enough about the  
> binding code to trace that either.  I'll try this pattern here, although  
> it would be nice if the bound array would work without these methods.

Has the proposed solution worked? I don't think you need to dive into  
binding code here, just put some breakpoints in the get and set methods in  
your page.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Fwd: Loop & Form

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Jul 24, 2009 at 3:13 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> I would try this:
>
> <td t:type="loop" source="matrix.columnTypes" value="columnType"
> t:index="index">
>
> @SuppressWarnings("unused")
> @Property
> private int index;
>
> public ColumnType getColumnType() {
>        return matrix.columnTypes[i].
> }
>
> public void setColumnType(ColumnType type) {
>        matrix.columnTypes[i] = type;
> }
>
> As far as I recall, that's similar to my working form. I don't have access
> to it anymore, but I'm sure it used to work. :)
>

The processFormSubmission() code seems to be working, so possibly an issue
with bindings, loops and arrays?  I don't know enough about the binding code
to trace that either.  I'll try this pattern here, although it would be nice
if the bound array would work without these methods.

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Fwd: Loop & Form

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 24 Jul 2009 15:53:01 -0300, Geoffrey Wiseman  
<ge...@gmail.com> escreveu:

> <td t:type="loop" source="matrix.columnTypes" value="columnType">

I would try this:

<td t:type="loop" source="matrix.columnTypes" value="columnType"  
t:index="index">

@SuppressWarnings("unused")
@Property
private int index;

public ColumnType getColumnType() {
	return matrix.columnTypes[i].
}

public void setColumnType(ColumnType type) {
	matrix.columnTypes[i] = type;
}

As far as I recall, that's similar to my working form. I don't have access  
to it anymore, but I'm sure it used to work. :)

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Fwd: Loop & Form

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Jul 24, 2009 at 2:43 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Strictly speaking, it doesn't iteract. This is done through bindings (for
> form fields, tipically the prop one).
> Could you post your form template? I've used a Grid editing a list of
> objects without any hassle, but I've never tested it with an array nor with
> a Loop.
>

Sure; I could easily switch it to a list as opposed to an array if that
would be more likely to work.  I might be able to adapt it to a grid,
although it's really just the header row that's part of the form -- the
other bits I set to volatile because they're really only there for display
purposes:

<t:form>

<t:errors />

<table class="grid">

<thead>

<tr>

<td t:type="loop" source="matrix.columnTypes" value="columnType">

<t:select value="columnType" />

</td>

</tr>

</thead>

<tbody>

<tr t:type="loop" source="matrix" value="row" volatile="true">

<td t:type="loop" source="row" value="cell" volatile="true">${cell}</td>

</tr>

</tbody>

</table>

<a t:type="pagelink" page="admin/exercise/participant/Upload" context="
exercise.id" t:mixins="yui/Button"><t:message key="back.button">Cancel</
t:message></a>

<t:submit t:id="next" t:mixins="yui/Button" value="message:next.button" />

</t:form>


Bound to:

@Property

@SessionState(create = false)

private UserUploadMatrix matrix;


 @SuppressWarnings("unused")

@Property

private String[] row;


 @Property

@SuppressWarnings("unused")

private ColumnType columnType;


 /**

 * Storage for a loop; iterating across the cells in a row.

 */

@SuppressWarnings("unused")

@Property

private String cell;


  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Fwd: Loop & Form

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 24 Jul 2009 15:26:00 -0300, Geoffrey Wiseman  
<ge...@gmail.com> escreveu:

> Ok, I'll follow that chain with the Select component, see where it leads  
> me. How does that interact with a Loop?

Strictly speaking, it doesn't iteract. This is done through bindings (for  
form fields, tipically the prop one).
Could you post your form template? I've used a Grid editing a list of  
objects without any hassle, but I've never tested it with an array nor  
with a Loop.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Fwd: Loop & Form

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Jul 24, 2009 at 1:25 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Fri, 24 Jul 2009 13:44:35 -0300, Geoffrey Wiseman <
> geoffrey.wiseman@gmail.com> escreveu:
>>
>> Even suggestions on where to debug and diagnose would be nice; I'm digging
>> around inside Form and Loop, but I don't yet understand what part of
>> Tapestry takes the response values in the form POST and tries to apply
>> them back to the bound object model.
>>
>
> Look at the field components (any org.apache.tapestry5.Field subclass,
> specially the AbstractField subclasses) and their processSubmission(String
> elementName) methods. Form does not handle fields values, the field
> components are the ones responsible for this.


Ok, I'll follow that chain with the Select component, see where it leads me.
 How does that interact with a Loop?


> You can also make sure that the same array instance is used during
> rendering and form submission.


In this case, the array is part of an object in @SessionState, so it should
be the same instance.

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/

Re: Fwd: Loop & Form

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Fri, 24 Jul 2009 13:44:35 -0300, Geoffrey Wiseman  
<ge...@gmail.com> escreveu:

> Even suggestions on where to debug and diagnose would be nice; I'm  
> digging around inside Form and Loop, but I don't yet understand what  
> part of
> Tapestry takes the response values in the form POST and tries to apply  
> them back to the bound object model.

Look at the field components (any org.apache.tapestry5.Field subclass,  
specially the AbstractField subclasses) and their processSubmission(String  
elementName) methods. Form does not handle fields values, the field  
components are the ones responsible for this.
You can also make sure that the same array instance is used during  
rendering and form submission.

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Fwd: Loop & Form

Posted by Geoffrey Wiseman <ge...@gmail.com>.
On Fri, Jul 24, 2009 at 12:31 PM, Geoffrey Wiseman <
geoffrey.wiseman@gmail.com> wrote:

> I'm dealing with my first loop-and-form and it's not behaving as I'd hoped,
> so I'm looking for some thoughts.
>

Even suggestions on where to debug and diagnose would be nice; I'm digging
around inside Form and Loop, but I don't yet understand what part of
Tapestry takes the response values in the form POST and tries to apply them
back to the bound object model.

  - Geoffrey
-- 
Geoffrey Wiseman
http://www.geoffreywiseman.ca/