You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Inge Solvoll <in...@gmail.com> on 2009/12/14 09:45:59 UTC

Custom ordering of fields

Hi!

In Struts, I implemented a way to let the customer decide the ordering of
form fields. It is done by specifying a list of keywords that each identify
a part of the form (most often a field) to include. These keywords are put
in a comma separated configuration string, that looks something like this:

firstName,lastName,address,phoneNumber,zip,city

I implemented it in struts by putting each form section inside a bean with
id=<keyword above, like lastName>, defining but not rendering the content.
Then I put a loop at the bottom that goes through the keywords and renders
the bean with the current keyword. The content then appears in the order
specified in the configuration. This approach works very well for us, we are
able to easily customize our forms by reordering, adding and removing fields
in a rather transparent way. It also works nicely for data output, where
content needs to be printed in a specific order, sometimes leaving something
out.

I've tried to implement this in T5, but it is one of the few things we
haven't yet managed to figure out. The obvious choice is to use blocks,
which seems almost equivalent to bean:define in struts. But there is a
catch: Our app has support for dynamic form fields. Meaning that our
customers can "build" parts of their forms themselves. This means that these
"custom fields" is rendered by retrieving information about these fields
from our database, and looping over the info in the tml, creating the
markup.

I tried doing this, but generated ids for blocks isn't allowed:

{t:block id="${currentCustomFieldKey}">
  {t:label for="currentCustomField"}
  {input type="text" t:id="currentCustomField"
value="currentCustomField.value"}
{/t:block}

I then tried to do this:

{{t:block t:id="customField">}

hoping that the t:id part would make T5 generate blocks named "customField",
"customField_0", "customField_1". But when I do a lookup on these blocks in
the page class, I only find the "customField" one, "customField_0" and
"customField_1" are null.

Does this description make sense to you, do you understand my problem and
what I'm trying to do? Some of you (me included) would probably say that it
seems a bit overkill to have forms that is customizable in 2 ways like I'm
describing here. The latter one could probably be left out, it was created
before we got the other idea. But short term, we have to keep it this way.
But I would really like to migrate the pages using the system to T5, I don't
want to wait for the bigger refactoring that may never happen.

If anyone is still reading, I would LOVE some input :)

Inge

Re: Custom ordering of fields

Posted by Inge Solvoll <in...@gmail.com>.
One more thing

I managed to solve this by parsing the DOM in afterRender and moving the
elements around there. But I don't find this approach very attractive, and
would like to find a way to do it with blocks.

On Mon, Dec 14, 2009 at 9:45 AM, Inge Solvoll <in...@gmail.com>wrote:

> Hi!
>
> In Struts, I implemented a way to let the customer decide the ordering of
> form fields. It is done by specifying a list of keywords that each identify
> a part of the form (most often a field) to include. These keywords are put
> in a comma separated configuration string, that looks something like this:
>
> firstName,lastName,address,phoneNumber,zip,city
>
> I implemented it in struts by putting each form section inside a bean with
> id=<keyword above, like lastName>, defining but not rendering the content.
> Then I put a loop at the bottom that goes through the keywords and renders
> the bean with the current keyword. The content then appears in the order
> specified in the configuration. This approach works very well for us, we are
> able to easily customize our forms by reordering, adding and removing fields
> in a rather transparent way. It also works nicely for data output, where
> content needs to be printed in a specific order, sometimes leaving something
> out.
>
> I've tried to implement this in T5, but it is one of the few things we
> haven't yet managed to figure out. The obvious choice is to use blocks,
> which seems almost equivalent to bean:define in struts. But there is a
> catch: Our app has support for dynamic form fields. Meaning that our
> customers can "build" parts of their forms themselves. This means that these
> "custom fields" is rendered by retrieving information about these fields
> from our database, and looping over the info in the tml, creating the
> markup.
>
> I tried doing this, but generated ids for blocks isn't allowed:
>
> {t:block id="${currentCustomFieldKey}">
>   {t:label for="currentCustomField"}
>   {input type="text" t:id="currentCustomField"
> value="currentCustomField.value"}
> {/t:block}
>
> I then tried to do this:
>
> {{t:block t:id="customField">}
>
> hoping that the t:id part would make T5 generate blocks named
> "customField", "customField_0", "customField_1". But when I do a lookup on
> these blocks in the page class, I only find the "customField" one,
> "customField_0" and "customField_1" are null.
>
> Does this description make sense to you, do you understand my problem and
> what I'm trying to do? Some of you (me included) would probably say that it
> seems a bit overkill to have forms that is customizable in 2 ways like I'm
> describing here. The latter one could probably be left out, it was created
> before we got the other idea. But short term, we have to keep it this way.
> But I would really like to migrate the pages using the system to T5, I don't
> want to wait for the bigger refactoring that may never happen.
>
> If anyone is still reading, I would LOVE some input :)
>
> Inge
>

Re: Custom ordering of fields

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Mon, 14 Dec 2009 06:45:59 -0200, Inge Solvoll <in...@gmail.com>  
escreveu:

> Hi!

Hi!

Why don't you use BeanEditor (or BeanEditForm) and handle the fields by  
creating and manipulating a BeanModel and its PropertyModels?

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, software architect and developer, Ars Machina Tecnologia da  
Informação Ltda.
http://www.arsmachina.com.br

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