You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by David Legg <da...@searchevent.co.uk> on 2010/01/19 11:34:29 UTC

Adding a form field at run time... is it possible?

Hi,

Is it possible to add new form fields at run time?

I'm new to Wicket and was hoping this framework would allow me to write 
a data driven editor.  The idea is to get the data's schema at run time 
and then automatically create a suitable form to allow a user to edit 
the data.

Everything was going well until it dawned on me that the markup page has 
to include all the Wicket tags to match the Wicket components and if 
they don't you get an exception.

But if that's the case how does Wicket handle forms where you click a 
button on the web page to add an extra field?

Regards,
David Legg


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


Re: Adding a form field at run time... is it possible?

Posted by Alexander Elsholz <al...@widas.de>.
hi,

use a listview. the model contains wicket-components that you put on listview.
if you have different html-elements introduce a wrapper: TextfieldWrapper,
SpanWrapper etc what are panels that wrapps the component.

alex






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


Re: CheckBoxMultipleChoice used in a Wizard Panel

Posted by Igor Vaynberg <ig...@gmail.com>.
if there were no validation errors the selected list should be
available in the model.

-igor

On Tue, Jan 19, 2010 at 5:48 AM, Riccardo Trombini
<ri...@csnc.ch> wrote:
> Hi !
>
> I am having problems with a CheckBoxMultipleChoice which I use in a
> DynamicWizardStep. I am not able to access the list with the checked
> boxes. I try to access on the list by adding an AbstractFormValidator
> and overwriting the method validate.
>
>
> public final class DetailWriteArticleStep extends
> CustomDynamicWizardStep {
>
>        private IDynamicWizardStep nextStep;
>        private RequiredTextField<String> titel;
>
>        public DetailWriteArticleStep(...) {
>                ...
>
>                final Input input = new Input(article.getCategory());
>                CheckBoxMultipleChoice categoriySelect = new
> CheckBoxMultipleChoice("choices",
>                                access.getCategories(),
>                                new ChoiceRenderer("categoryName",
> "categoryId"));
>        categoriySelect.setDefaultModelObject(input);
>                add(categoriySelect);
>                System.out.println( input.choices.size());
>
>                add(new AbstractFormValidator() {
>                public void validate(Form<?> form) {
>
> System.out.println(article.getCategory().size());
>                        }
>                }
> }
>
>
> public class Input implements IClusterable{
>
>    /** the selected choices. */
>    public List choices = new ArrayList();
>
>    /** adds pre-selected items to the choices list */
>    public Input(Article article){
>        for(int i = 0 ; i < article.getCategory().size() ; i++){
>                this.choices.add(article.getCategory().get(i));
>        }
>    }
>
>    /** adds pre-selected items to the choices list */
>    public Input(ArrayList list){
>        for(int i = 0 ; i < list.size() ; i++){
>                this.choices.add(list.get(i));
>        }
>    }
> }
>
>
>
> I also tried to add the Object article with the property "Category" as
> the propertyModel of the CheckBoxMultipleChoice but this worked
> neighter. The size of the List was always 0.
>
> Can anyone help me ?
>
> Thx !
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: CheckBoxMultipleChoice used in a Wizard Panel

Posted by nunofaria11 <nu...@gmail.com>.
Hi there, 
I am having the same problem you had regarding a CheckBoxMultipleChoice used
in a Wizard Panel: the list within the model containing the chosen items is
always empty. Were you able to solve that problem? And if so, how?

Thanks
Nuno

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Adding-a-form-field-at-run-time-is-it-possible-tp1877626p4642679.html
Sent from the Users forum mailing list archive at Nabble.com.

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


CheckBoxMultipleChoice used in a Wizard Panel

Posted by Riccardo Trombini <ri...@csnc.ch>.
Hi !

I am having problems with a CheckBoxMultipleChoice which I use in a
DynamicWizardStep. I am not able to access the list with the checked
boxes. I try to access on the list by adding an AbstractFormValidator
and overwriting the method validate.


public final class DetailWriteArticleStep extends
CustomDynamicWizardStep {

    	private IDynamicWizardStep nextStep;
	private RequiredTextField<String> titel;

    	public DetailWriteArticleStep(...) {
        	...
        
        	final Input input = new Input(article.getCategory());
        	CheckBoxMultipleChoice categoriySelect = new
CheckBoxMultipleChoice("choices", 
				access.getCategories(),
				new ChoiceRenderer("categoryName",
"categoryId"));
       	categoriySelect.setDefaultModelObject(input);
        	add(categoriySelect);
        	System.out.println( input.choices.size());
	        
		add(new AbstractFormValidator() {
            	public void validate(Form<?> form) {
 
System.out.println(article.getCategory().size());
			}
		}
}


public class Input implements IClusterable{

    /** the selected choices. */
    public List choices = new ArrayList();

    /** adds pre-selected items to the choices list */
    public Input(Article article){
    	for(int i = 0 ; i < article.getCategory().size() ; i++){
    		this.choices.add(article.getCategory().get(i));
    	}
    }
    
    /** adds pre-selected items to the choices list */
    public Input(ArrayList list){
    	for(int i = 0 ; i < list.size() ; i++){
    		this.choices.add(list.get(i));
    	}
    }
}



I also tried to add the Object article with the property "Category" as
the propertyModel of the CheckBoxMultipleChoice but this worked
neighter. The size of the List was always 0.

Can anyone help me ?

Thx !

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


Re: Adding a form field at run time... is it possible?

Posted by David Legg <da...@searchevent.co.uk>.
Thanks again Martin, Pedro and Martijn.

I've had that Aha! moment when something comes into focus!

I understand now what Pedro meant about templates.  Also I've had a 
quick peek at WicketWebBeans (WWB).  I see that WWB effectively creates 
a specialist Wicket component that does most of what I wanted).  So I 
think I'm good to go!

Thanks again for the very friendly welcome to Wicket.

Regards,
David Legg


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


Re: Adding a form field at run time... is it possible?

Posted by Martijn Dashorst <ma...@gmail.com>.
Did you read [1] ?

Martijn

[1] http://wicketinaction.com/2008/10/building-a-listeditor-form-component/

On Tue, Jan 19, 2010 at 1:59 PM, David Legg
<da...@searchevent.co.uk> wrote:
> Thanks for the ideas Martin + Pedro.
>
> It looks as if I'm trying to do something Wicket isn't designed for ;-)
>
> I wonder if another technique would be to dynamically modify the markup
> using the DOM to add the missing wicket markers as required before rendering
> takes place.
>
> Anyway thanks again for the pointers; I'll take a closer look at
> WicketWebBeans as mentioned in the thread you gave me too.
>
> Regards,
> David Legg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.4 increases type safety for web applications
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.4.4

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


Re: Adding a form field at run time... is it possible?

Posted by Pedro Santos <pe...@gmail.com>.
Wicket tags are meant to be used to make an template. The final markup will
to be generated from that template.
Do you realize that you are talking about dynamically generate an template?
There is no need for. Take a closer look at repeaters.

On Tue, Jan 19, 2010 at 10:59 AM, David Legg
<da...@searchevent.co.uk>wrote:

> Thanks for the ideas Martin + Pedro.
>
> It looks as if I'm trying to do something Wicket isn't designed for ;-)
>
> I wonder if another technique would be to dynamically modify the markup
> using the DOM to add the missing wicket markers as required before rendering
> takes place.
>
> Anyway thanks again for the pointers; I'll take a closer look at
> WicketWebBeans as mentioned in the thread you gave me too.
>
>
> Regards,
> David Legg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos

RE: Adding a form field at run time... is it possible?

Posted by Martin Asenov <mA...@velti.com>.
David, I'm pretty sure that everything you want could be accomplished through Wicket. Anyway, if you describe the use case completely, I can give further advices on what to do.

Regards,
Martin

-----Original Message-----
From: David Legg [mailto:david.legg@searchevent.co.uk] 
Sent: Tuesday, January 19, 2010 2:59 PM
To: users@wicket.apache.org
Subject: Re: Adding a form field at run time... is it possible?

Thanks for the ideas Martin + Pedro.

It looks as if I'm trying to do something Wicket isn't designed for ;-)

I wonder if another technique would be to dynamically modify the markup 
using the DOM to add the missing wicket markers as required before 
rendering takes place.

Anyway thanks again for the pointers; I'll take a closer look at 
WicketWebBeans as mentioned in the thread you gave me too.

Regards,
David Legg


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


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


Re: Adding a form field at run time... is it possible?

Posted by David Legg <da...@searchevent.co.uk>.
Thanks for the ideas Martin + Pedro.

It looks as if I'm trying to do something Wicket isn't designed for ;-)

I wonder if another technique would be to dynamically modify the markup 
using the DOM to add the missing wicket markers as required before 
rendering takes place.

Anyway thanks again for the pointers; I'll take a closer look at 
WicketWebBeans as mentioned in the thread you gave me too.

Regards,
David Legg


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


Re: Adding a form field at run time... is it possible?

Posted by Pedro Santos <pe...@gmail.com>.
> Everything was going well until it dawned on me that the markup page has
to include all the Wicket tags to match the Wicket > > > components and if
they don't you get an exception.

You can override the onComponentTag method from the component that is
throwing the exception, and remove the tag validation.

You can have more ideas to assembly your from on:

http://old.nabble.com/dynamic-components-td26244887.html
<http://old.nabble.com/dynamic-components-td26244887.html>

On Tue, Jan 19, 2010 at 8:34 AM, David Legg <da...@searchevent.co.uk>wrote:

> Hi,
>
> Is it possible to add new form fields at run time?
>
> I'm new to Wicket and was hoping this framework would allow me to write a
> data driven editor.  The idea is to get the data's schema at run time and
> then automatically create a suitable form to allow a user to edit the data.
>
> Everything was going well until it dawned on me that the markup page has to
> include all the Wicket tags to match the Wicket components and if they don't
> you get an exception.
>
> But if that's the case how does Wicket handle forms where you click a
> button on the web page to add an extra field?
>
> Regards,
> David Legg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Pedro Henrique Oliveira dos Santos

RE: Adding a form field at run time... is it possible?

Posted by Martin Asenov <mA...@velti.com>.
Hi David,

You may try to separate different forms into different panels, since panels have their own markup. They will hold specific forms suitable for your needs.

Anyway, if you just need to include only one extra field, you can put it there, but do as follows:

extraField.setOutputPlaceHolderTag(true);
extraField.setVisible(false);

and when some event happens, i.e. hitting a button to say within onSubmit(ART target) {
extraField.setVisible(true);
target.addComponent(extraField);
}

hope that helps!
Regards,
Martin

-----Original Message-----
From: David Legg [mailto:david.legg@searchevent.co.uk] 
Sent: Tuesday, January 19, 2010 12:34 PM
To: users@wicket.apache.org
Subject: Adding a form field at run time... is it possible?

Hi,

Is it possible to add new form fields at run time?

I'm new to Wicket and was hoping this framework would allow me to write 
a data driven editor.  The idea is to get the data's schema at run time 
and then automatically create a suitable form to allow a user to edit 
the data.

Everything was going well until it dawned on me that the markup page has 
to include all the Wicket tags to match the Wicket components and if 
they don't you get an exception.

But if that's the case how does Wicket handle forms where you click a 
button on the web page to add an extra field?

Regards,
David Legg


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


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