You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Eric Rotick <pc...@gmail.com> on 2008/03/19 17:21:51 UTC
Adding dynamic form components to forms
I would like to be able to create a form where the number and type of form
component is decided at run time.
I've done the research and found various guides, e.g
http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html but I've not
managed to crack it yet.
I've created some panels for the form components, one for a fieldset and one
for the form.
<wicket:panel>
<input type="text" wicket:id="textValue">
</wicket:panel>
<wicket:panel>
<fieldset>
<legend wicket:id="setName">setName</legend>
<table>
<tr wicket:id="eachEntry">
<td wicket:id="fieldName">fieldName</td>
<td wicket:id="fieldValue">fieldValue</td>
</tr>
</table>
</fieldset>
</wicket:panel>
<wicket:panel>
<form wicket:id="SingleItemFormName">
<span wicket:id="SingleItemFormContents"/>
</form>
</wicket:panel>
When I use this
final Form form = new Form( "SingleItemFormName" );
for( Iterator views = display.getViews( ).iterator( ); views.hasNext( );
) {
IView view = (IView) views.next( );
form.add( new FieldSetView( "SingleItemFormContents", readonly,
display, data, view ) );
}
add( form );
it works but only if there is one view. The reason is clear so I thought
this is the time to use a ListView. Note that I believe the code above shows
that the markup and panels are all working OK but the second time I use the
same id it barfs.
If I use this
final Form form = new Form( "SingleItemFormName" );
ListView contents = new ListView( "SingleItemFormContents",
display.getViews( ) ) {
protected void populateItem( ListItem item ) {
IView view = (IView) item.getModelObject( );
item.add( new FieldSetView( view.getName( ), readonly, display,
data, view ) );
}
};
contents.setReuseItems( true );
form.add( contents );
add( form );
I get the error that components failed to render.
I've also tried
final Form form = new Form( "SingleItemFormName" );
add( form );
ListView contents = new ListView( "SingleItemFormContents",
display.getViews( ) ) {
protected void populateItem( ListItem item ) {
IView view = (IView) item.getModelObject( );
item.add( new FieldSetView( view.getName( ), readonly, display,
data, view ) );
}
};
contents.setReuseItems( true );
add( contents );
form.add( contents );
and even
final Form form = new Form( "SingleItemFormName" );
WebMarkupContainer wmc = new WebMarkupContainer(
"SingleItemFormContents" );
for( Iterator views = display.getViews( ).iterator( ); views.hasNext( );
) {
IView view = (IView) views.next( );
wmc.add( new FieldSetView( view.getName( ), readonly, display, data,
view ) );
}
form.add( wmc );
but they all say that components failed to render.
What am I missing?
Thanks.
Re: Adding dynamic form components to forms
Posted by Igor Vaynberg <ig...@gmail.com>.
see http://herebebeasties.com/2007-08-17/wicket-bean-editor/
there is also a wicketstuff-crud project that does this...
-igor
On Wed, Mar 19, 2008 at 9:21 AM, Eric Rotick <pc...@gmail.com> wrote:
> I would like to be able to create a form where the number and type of form
> component is decided at run time.
>
> I've done the research and found various guides, e.g
> http://cwiki.apache.org/WICKET/forms-with-dynamic-elements.html but I've not
> managed to crack it yet.
>
> I've created some panels for the form components, one for a fieldset and one
> for the form.
>
> <wicket:panel>
> <input type="text" wicket:id="textValue">
> </wicket:panel>
>
> <wicket:panel>
> <fieldset>
> <legend wicket:id="setName">setName</legend>
> <table>
> <tr wicket:id="eachEntry">
> <td wicket:id="fieldName">fieldName</td>
> <td wicket:id="fieldValue">fieldValue</td>
> </tr>
> </table>
> </fieldset>
> </wicket:panel>
>
> <wicket:panel>
> <form wicket:id="SingleItemFormName">
> <span wicket:id="SingleItemFormContents"/>
> </form>
> </wicket:panel>
>
> When I use this
>
> final Form form = new Form( "SingleItemFormName" );
>
> for( Iterator views = display.getViews( ).iterator( ); views.hasNext( );
> ) {
> IView view = (IView) views.next( );
> form.add( new FieldSetView( "SingleItemFormContents", readonly,
> display, data, view ) );
> }
>
> add( form );
>
> it works but only if there is one view. The reason is clear so I thought
> this is the time to use a ListView. Note that I believe the code above shows
> that the markup and panels are all working OK but the second time I use the
> same id it barfs.
>
> If I use this
>
> final Form form = new Form( "SingleItemFormName" );
>
> ListView contents = new ListView( "SingleItemFormContents",
> display.getViews( ) ) {
> protected void populateItem( ListItem item ) {
> IView view = (IView) item.getModelObject( );
> item.add( new FieldSetView( view.getName( ), readonly, display,
> data, view ) );
> }
> };
> contents.setReuseItems( true );
>
> form.add( contents );
>
> add( form );
>
> I get the error that components failed to render.
>
> I've also tried
>
> final Form form = new Form( "SingleItemFormName" );
> add( form );
>
> ListView contents = new ListView( "SingleItemFormContents",
> display.getViews( ) ) {
> protected void populateItem( ListItem item ) {
> IView view = (IView) item.getModelObject( );
> item.add( new FieldSetView( view.getName( ), readonly, display,
> data, view ) );
> }
> };
> contents.setReuseItems( true );
> add( contents );
>
> form.add( contents );
>
> and even
>
> final Form form = new Form( "SingleItemFormName" );
>
> WebMarkupContainer wmc = new WebMarkupContainer(
> "SingleItemFormContents" );
> for( Iterator views = display.getViews( ).iterator( ); views.hasNext( );
> ) {
> IView view = (IView) views.next( );
> wmc.add( new FieldSetView( view.getName( ), readonly, display, data,
> view ) );
> }
> form.add( wmc );
>
> but they all say that components failed to render.
>
> What am I missing?
>
> Thanks.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org