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

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

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

David Legg
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Martin Asenov
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:[hidden email]]
Sent: Tuesday, January 19, 2010 12:34 PM
To: [hidden email]
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: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Pedro Santos
In reply to this post by David Legg
> 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 <[hidden email]>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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Pedro Henrique Oliveira dos Santos
Reply | Threaded
Open this post in threaded view
|

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

David Legg
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Martin Asenov
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:[hidden email]]
Sent: Tuesday, January 19, 2010 2:59 PM
To: [hidden email]
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: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

Pedro Santos
In reply to this post by David Legg
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
<[hidden email]>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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Pedro Henrique Oliveira dos Santos
Reply | Threaded
Open this post in threaded view
|

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

Martijn Dashorst
Administrator
In reply to this post by David Legg
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
<[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



--
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

CheckBoxMultipleChoice used in a Wizard Panel

Riccardo Trombini
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

David Legg
In reply to this post by Martijn Dashorst
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: CheckBoxMultipleChoice used in a Wizard Panel

Igor Vaynberg-2
In reply to this post by Riccardo Trombini
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
<[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

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

alexander elsholz
In reply to this post by David Legg
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: CheckBoxMultipleChoice used in a Wizard Panel

nunofaria11
In reply to this post by Riccardo Trombini
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