You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by nazeem <md...@gmail.com> on 2011/10/18 14:00:01 UTC
wicket - form debug
I have simple case, which worked for me in another project but failed in the
current one. Both use same set of libraries. I am doing something wrong,
could not trace it down. Please help to debug this.
I am designing a reusable form & textfield component, which will have
provision to show feedback beneath each text field and so on. The problem I
am facing is, MyTextField is a border which in turn contains TextField, this
text field is set as required = true, when i submit the form, onSubmit from
the submit button gets called instead of onError.
But if I add a plain raw textfield directly to MyFormBorder it works as
expected, i.e onError is called when no value is entered.
How do I debug this problem ? Please assist. I am using wicket 1.4.19
Code Below
------------
public class MyFormBorder extends Border {
FeedbackPanel fbp;
Form form;
public MyFormBorder(String id, IModel model) {
super(id);
fbp = new FeedbackPanel("feedback");
fbp.setOutputMarkupId(true);
add(fbp);
form = new Form("form", model);
form.add(getBodyContainer());
add(form);
}
public void onError(AjaxRequestTarget target, Form form) {
if(form.hasFeedbackMessage()) {
fbp.info(form.getFeedbackMessage().getMessage().toString());
}
target.addComponent(fbp);
}
public Form getForm() {
return form;
}
}
Html
-----
<wicket:border>
<div wicket:id="feedback"></div>
<form wicket:id="form" class="form">
<wicket:body/>
</form>
</wicket:border>
TextField
---------
public class MyTextField extends Border {
ComponentFeedbackPanel cfbp;
TextField textField;
WebMarkupContainer cntr = new WebMarkupContainer("cntr");
public MyTextField(String id, String label, IModel model, boolean required)
{
super(id);
cntr.setOutputMarkupId(true);
cntr.add(new Label("label", label));
textField = new TextField("textfield", model);
textField.setLabel(new Model(label));
textField.setRequired(required);
cntr.add(textField);
cfbp = new ComponentFeedbackPanel("cfbp", textField);
cfbp.setOutputMarkupId(true);
cfbp.setVisible(false);
cntr.add(cfbp);
cntr.add(getBodyContainer());
add(cntr);
}
}
HTML
-----
<wicket:border>
<div wicket:id="cntr" class="type-text">
<strong wicket:id="cfbp" class="message"></strong>
<label for="" wicket:id="label"></label>
<input wicket:id="textfield" style="" type="text"></input>
<wicket:body/>
<wicket:child/>
</div>
</wicket:border>
I am using these myformborder & mytextfield as below
Menu menu = new Menu();
MyFormBorder myFormBorder = new MyFormBorder("ffborder", new Model(menu));
MyTextField ftf = new MyTextField("name", "Menu Name", new
PropertyModel(menu, "name"), true);
myFormBorder.add(ftf);
// Without the following textfield getting directly added, onError is not
called for the above text field
TextField tf = new TextField("desc", new PropertyModel(menu,
"description"));
tf.setRequired(true);
forceFormBorder.add(tf);
AjaxSubmitButton submit = new AjaxSubmitButton("submit",
forceFormBorder.getForm()) {
@Override
protected void onSubmit(AjaxRequestTarget arg0, Form<?> arg1) {
System.out.println("onSubmit...");
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
System.out.println("onError...");
}
};
forceFormBorder.add(submit);
add(forceFormBorder);
HTML
-----
<div wicket:id="ffborder">
<div wicket:id="name"></div>
<input type="text" wicket:id="desc"/>
# Submit
</div>
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915041.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
Re: wicket - form debug
Posted by nazeem <md...@gmail.com>.
Wow ! it worked. Thank you so much. So i did not understand the borders
well.. :)
I am developing a component library on wicket and I enjoy doing it, and it
gives great productivity boost to the developers and helps to get the look
and feel consistent. Thank you so much for the support.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915889.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
Re: wicket - form debug
Posted by Igor Vaynberg <ig...@gmail.com>.
myFormBorder.getBodyContainer().add(ftf) should do it.
-igor
On Tue, Oct 18, 2011 at 8:40 AM, nazeem <md...@gmail.com> wrote:
> Thanks Igor. I was mislead by seeing the generated html. In the rendered html
> the textfield is inside, but from the code, I am adding the MyTextField to
> the border and not to the form.
>
> In MyFormBorder I am adding the contents to the form, will this not solve ?
>
> form.add(getBodyContainer());
>
> I also tried this, but it gives me error saying name field not found.
>
> myFormBorder.getForm().add(ftf);
>
> Any other suggestions please.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915794.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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: wicket - form debug
Posted by nazeem <md...@gmail.com>.
Thanks Igor. I was mislead by seeing the generated html. In the rendered html
the textfield is inside, but from the code, I am adding the MyTextField to
the border and not to the form.
In MyFormBorder I am adding the contents to the form, will this not solve ?
form.add(getBodyContainer());
I also tried this, but it gives me error saying name field not found.
myFormBorder.getForm().add(ftf);
Any other suggestions please.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915794.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
Re: wicket - form debug
Posted by Igor Vaynberg <ig...@gmail.com>.
myFormBorder.add(ftf);
this line adds the textfield outside the form, so your form stays
empty thus validation passes.
-igor
On Tue, Oct 18, 2011 at 5:00 AM, nazeem <md...@gmail.com> wrote:
> I have simple case, which worked for me in another project but failed in the
> current one. Both use same set of libraries. I am doing something wrong,
> could not trace it down. Please help to debug this.
>
> I am designing a reusable form & textfield component, which will have
> provision to show feedback beneath each text field and so on. The problem I
> am facing is, MyTextField is a border which in turn contains TextField, this
> text field is set as required = true, when i submit the form, onSubmit from
> the submit button gets called instead of onError.
>
> But if I add a plain raw textfield directly to MyFormBorder it works as
> expected, i.e onError is called when no value is entered.
>
> How do I debug this problem ? Please assist. I am using wicket 1.4.19
>
> Code Below
> ------------
>
> public class MyFormBorder extends Border {
>
> FeedbackPanel fbp;
> Form form;
>
> public MyFormBorder(String id, IModel model) {
> super(id);
> fbp = new FeedbackPanel("feedback");
> fbp.setOutputMarkupId(true);
> add(fbp);
>
> form = new Form("form", model);
> form.add(getBodyContainer());
> add(form);
> }
>
> public void onError(AjaxRequestTarget target, Form form) {
> if(form.hasFeedbackMessage()) {
> fbp.info(form.getFeedbackMessage().getMessage().toString());
> }
> target.addComponent(fbp);
> }
>
> public Form getForm() {
> return form;
> }
> }
>
>
> Html
> -----
> <wicket:border>
> <div wicket:id="feedback"></div>
> <form wicket:id="form" class="form">
> <wicket:body/>
> </form>
> </wicket:border>
>
>
> TextField
> ---------
> public class MyTextField extends Border {
>
> ComponentFeedbackPanel cfbp;
> TextField textField;
> WebMarkupContainer cntr = new WebMarkupContainer("cntr");
>
> public MyTextField(String id, String label, IModel model, boolean required)
> {
> super(id);
> cntr.setOutputMarkupId(true);
> cntr.add(new Label("label", label));
>
> textField = new TextField("textfield", model);
> textField.setLabel(new Model(label));
> textField.setRequired(required);
> cntr.add(textField);
>
> cfbp = new ComponentFeedbackPanel("cfbp", textField);
> cfbp.setOutputMarkupId(true);
> cfbp.setVisible(false);
> cntr.add(cfbp);
>
> cntr.add(getBodyContainer());
> add(cntr);
> }
>
>
> }
>
> HTML
> -----
> <wicket:border>
> <div wicket:id="cntr" class="type-text">
> <strong wicket:id="cfbp" class="message"></strong>
> <label for="" wicket:id="label"></label>
> <input wicket:id="textfield" style="" type="text"></input>
> <wicket:body/>
> <wicket:child/>
> </div>
> </wicket:border>
>
>
> I am using these myformborder & mytextfield as below
>
> Menu menu = new Menu();
>
> MyFormBorder myFormBorder = new MyFormBorder("ffborder", new Model(menu));
>
> MyTextField ftf = new MyTextField("name", "Menu Name", new
> PropertyModel(menu, "name"), true);
> myFormBorder.add(ftf);
>
> // Without the following textfield getting directly added, onError is not
> called for the above text field
> TextField tf = new TextField("desc", new PropertyModel(menu,
> "description"));
> tf.setRequired(true);
> forceFormBorder.add(tf);
>
> AjaxSubmitButton submit = new AjaxSubmitButton("submit",
> forceFormBorder.getForm()) {
>
> @Override
> protected void onSubmit(AjaxRequestTarget arg0, Form<?> arg1) {
> System.out.println("onSubmit...");
> }
>
> @Override
> protected void onError(AjaxRequestTarget target, Form<?> form) {
> System.out.println("onError...");
> }
> };
> forceFormBorder.add(submit);
> add(forceFormBorder);
>
> HTML
> -----
> <div wicket:id="ffborder">
> <div wicket:id="name"></div>
> <input type="text" wicket:id="desc"/>
> # Submit
> </div>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/wicket-form-debug-tp3915041p3915041.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
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org