You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Cantrell <ca...@pobox.com> on 2006/05/21 00:06:35 UTC

Adding form elements with Javascript

Sorry to interject an actual Tapestry question into all the exciting  
talk about logos and GWT!

I have a form with a bunch of text fields inside a @For. I want my  
page to have a "new item" link that uses Javascript to add a new  
element to the form.

My Javascript works great on the client -- new TextFields appear just  
fine. But this adds unexpected components to my form, and of couse I  
get a stale link error.

How do I prevent the stale link? Do I use Javascript to manually  
modify the hidden field that lists the components in the form? i.e.  
use Javascript to turn this:

     <input type="hidden" name="formids"
         value="items,Hidden,TextField,Submit"/>

...into this:

     <input type="hidden" name="formids"
          
value="items,Hidden,TextField,Hidden,TextField,Hidden,TextField,Submit"/ 
 >

...? Yuck!

Is there a better way?

I'm sure this must have been covered on the list or in the docs, but  
I searched and couldn't find it. Any pointers in the right direct  
would be welcome.

Cheers,

Paul

_________________________________________________________________
Piano music podcast: http://inthehands.com
Other interesting stuff: http://innig.net



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


Re: Adding form elements with Javascript

Posted by Sam Gendler <sg...@ideasculptor.com>.
As far as I know, the only Tapestry-approved way of doing this is to
do a round-trip to the server - either to re-render the entire page,
or to re-render a section of the page via Tacos' ajax mechanism.  That
keeps the state of the page on the server and the html in sync so you
don't get the stale page error.  To my mind, this is Tap's single
greatest flaw, especially considering the general move to much more
dynamic content on the client.  It makes a lot of things that could be
done purely on the client prohibitively difficult.  Another option
would be to make the form post to an ExternalService and then manually
process the form parameters instead of letting Tapestry do it for you.
 But if you do that, you might as well just be working in a plain old
servlet.

--sam


On 5/20/06, Cliff Zhao <zh...@gmail.com> wrote:
> Let Tapestry renders all the components. You only use Javascript to make
> them visible or invisible. I think that this is the most straight forward
> way, otherwise you have to manipulate the rewind cycle, which is
> error-prone.
>
> On 5/20/06, Paul Cantrell <ca...@pobox.com> wrote:
> >
> > Sorry to interject an actual Tapestry question into all the exciting
> > talk about logos and GWT!
> >
> > I have a form with a bunch of text fields inside a @For. I want my
> > page to have a "new item" link that uses Javascript to add a new
> > element to the form.
> >
> > My Javascript works great on the client -- new TextFields appear just
> > fine. But this adds unexpected components to my form, and of couse I
> > get a stale link error.
> >
> > How do I prevent the stale link? Do I use Javascript to manually
> > modify the hidden field that lists the components in the form? i.e.
> > use Javascript to turn this:
> >
> >      <input type="hidden" name="formids"
> >          value="items,Hidden,TextField,Submit"/>
> >
> > ...into this:
> >
> >      <input type="hidden" name="formids"
> >
> > value="items,Hidden,TextField,Hidden,TextField,Hidden,TextField,Submit"/
> > >
> >
> > ...? Yuck!
> >
> > Is there a better way?
> >
> > I'm sure this must have been covered on the list or in the docs, but
> > I searched and couldn't find it. Any pointers in the right direct
> > would be welcome.
> >
> > Cheers,
> >
> > Paul
> >
> > _________________________________________________________________
> > Piano music podcast: http://inthehands.com
> > Other interesting stuff: http://innig.net
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>

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


Re: Adding form elements with Javascript

Posted by Cliff Zhao <zh...@gmail.com>.
Let Tapestry renders all the components. You only use Javascript to make
them visible or invisible. I think that this is the most straight forward
way, otherwise you have to manipulate the rewind cycle, which is
error-prone.

On 5/20/06, Paul Cantrell <ca...@pobox.com> wrote:
>
> Sorry to interject an actual Tapestry question into all the exciting
> talk about logos and GWT!
>
> I have a form with a bunch of text fields inside a @For. I want my
> page to have a "new item" link that uses Javascript to add a new
> element to the form.
>
> My Javascript works great on the client -- new TextFields appear just
> fine. But this adds unexpected components to my form, and of couse I
> get a stale link error.
>
> How do I prevent the stale link? Do I use Javascript to manually
> modify the hidden field that lists the components in the form? i.e.
> use Javascript to turn this:
>
>      <input type="hidden" name="formids"
>          value="items,Hidden,TextField,Submit"/>
>
> ...into this:
>
>      <input type="hidden" name="formids"
>
> value="items,Hidden,TextField,Hidden,TextField,Hidden,TextField,Submit"/
> >
>
> ...? Yuck!
>
> Is there a better way?
>
> I'm sure this must have been covered on the list or in the docs, but
> I searched and couldn't find it. Any pointers in the right direct
> would be welcome.
>
> Cheers,
>
> Paul
>
> _________________________________________________________________
> Piano music podcast: http://inthehands.com
> Other interesting stuff: http://innig.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>