You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by kamiseq <ka...@gmail.com> on 2012/05/15 01:50:03 UTC

wicket 6 dynamic form parts generated in JS

hej,
I would like to dynamically add same part to form, let say I have a
form that has a section with 3 inputs : start, end and name. those
section can occur many times depending on model.

this is very easy when depending on server logic and making full page
refresh every time users add section via link.
I would like to add such section from javascript, without server
interaction. the problem I see is that I need to generate names of
inputs in section witch will contain the right index so wicket knows
where to put data, right?

example

<form>
  <ol>
    <li wicket:id="each.section">
       <div wicket:id="form.part"></div>
    </li>
  </ol>
</form>
I created custom FormComponentPanel and overridden convertInput. and
added ListView to create list with panels.
when I looked on generated html, names of input where something like :
name="each.section:1:form.part:start, so I guess I could generate
something like that in JS but I wonder if this will not break wicket
logic. more even I hack those names creating elements in JS list will
not be synchronised with model on server and they will be removed when
user refreshes the page

I think the best way to do it is to make a round trip to server with
ajax and replace form content every time user clicks a button.

what do you think?

pozdrawiam
Paweł Kamiński

kamiseq@gmail.com
pkaminski.prv@gmail.com
______________________

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


Re: wicket 6 dynamic form parts generated in JS

Posted by kamiseq <ka...@gmail.com>.
ok, great.
this is what I thought so I dont want to reinvent things again, many
thanks for quick replay

pozdrawiam
Paweł Kamiński

kamiseq@gmail.com
pkaminski.prv@gmail.com
______________________

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


Re: wicket 6 dynamic form parts generated in JS

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

On Tue, May 15, 2012 at 1:50 AM, kamiseq <ka...@gmail.com> wrote:
> hej,
> I would like to dynamically add same part to form, let say I have a
> form that has a section with 3 inputs : start, end and name. those
> section can occur many times depending on model.
>
> this is very easy when depending on server logic and making full page
> refresh every time users add section via link.
> I would like to add such section from javascript, without server
> interaction. the problem I see is that I need to generate names of
> inputs in section witch will contain the right index so wicket knows
> where to put data, right?
>
> example
>
> <form>
>  <ol>
>    <li wicket:id="each.section">
>       <div wicket:id="form.part"></div>
>    </li>
>  </ol>
> </form>
> I created custom FormComponentPanel and overridden convertInput. and
> added ListView to create list with panels.
> when I looked on generated html, names of input where something like :
> name="each.section:1:form.part:start, so I guess I could generate
> something like that in JS but I wonder if this will not break wicket
> logic. more even I hack those names creating elements in JS list will
> not be synchronised with model on server and they will be removed when
> user refreshes the page
>
> I think the best way to do it is to make a round trip to server with
> ajax and replace form content every time user clicks a button.

This is the Wicket way. It is simple to develop.

Another (also Wicket) way is to generate the next row and make it
invisible, then with JS just make it visible and do an Ajax call to
add another invisible row for the next record. This way the model will
be in sync in the client and the server, but you have to be prepared
that the last row may be not used yet.

Yet another way is to create the form components dynamically with JS
and submit to a Page instead of a Form, i.e. <form>'s action will
point to a mounted page. This way when you submit you will have the
flexibility to handle any number of parameters, create a proper model
at the server side and visualize it later however you want.

>
> what do you think?
>
> pozdrawiam
> Paweł Kamiński
>
> kamiseq@gmail.com
> pkaminski.prv@gmail.com
> ______________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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