You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by vov <vo...@mail.ru> on 2010/06/18 12:11:26 UTC
AJAX Button does not submit form if RequiredTextField is empty
Form<Void> form = new Form<Void>("form");
form.add(new RequiredTextField<String>("filed"));
final TextField<String> textField;
form.add(textField = new TextField<String>("filed2", new
Model<String>()));
form.add(new AjaxButton("button")
{
@Override
protected void onSubmit(AjaxRequestTarget target,
@SuppressWarnings("hiding") Form<?> form)
{
System.out.println("Test." + textField.getConvertedInput());
System.out.println("Test." + textField.getModelObject());
}
});
In case if "filed" is empty than onSubmit() method does not call after
submitting button.
I can find only one solution - to override process() and onValidate()
methods of form as fallows:
Form<Void> form = new Form<Void>("form")
{
@Override
public void process(IFormSubmittingComponent submittingComponent)
{
if ("button".equals(submittingComponent.getInputName()))
{
getApplication().getSessionStore().setAttribute(getRequest(),
"button", true);
}
super.process(submittingComponent);
}
@SuppressWarnings("unchecked")
@Override
protected void onValidate()
{
if (getApplication().getSessionStore().getAttribute(getRequest(),
"unvalidate") != null
&& (Boolean)
getApplication().getSessionStore().getAttribute(getRequest(), "unvalidate"))
{
getApplication().getSessionStore().removeAttribute(getRequest(),
"button");
Session.get().getFeedbackMessages().clear();
return;
}
}
};
...but IMHO it's not good:)
What is the correct way to solve this problem?
thanks in advance
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AJAX-Button-does-not-submit-form-if-RequiredTextField-is-empty-tp2259981p2259981.html
Sent from the Wicket - User 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: AJAX Button does not submit form if RequiredTextField is empty
Posted by vov <vo...@mail.ru>.
Thanks for replay Stefan.
Nestet form is a good idea for my example.
But am so sorry that simplified it. In some cases there is not easy to make
markup using this way.
For example I want to use in my onSubmit method model value from 2 or 3
different TextFields or other FormComponents. And all of them are placed in
different part of form.
I found another answer on my question, but may be any standard solution
exists:
form.add(new AjaxButton("button")
{
@Override
protected void onSubmit(AjaxRequestTarget target,
@SuppressWarnings("hiding") Form<?> form)
{
textField.convertInput();
textField.updateModel();
System.out.println("Test." + textField.getConvertedInput());
System.out.println("Test." + textField.getModelObject());
}
}.setDefaultFormProcessing(false));
I set defaultFormProcessing to false and manually update neccessary
component.
But now I need create custom TextField...
class MyTextField<T> extends TextField<T>
{
public MyTextField(String id)
{
super(id);
}
@Override
public void convertInput()
{
super.convertInput();
}
}
...that make convertInput() method public
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AJAX-Button-does-not-submit-form-if-RequiredTextField-is-empty-tp2259981p2260054.html
Sent from the Wicket - User 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: AJAX Button does not submit form if RequiredTextField is empty
Posted by Stefan Lindner <li...@visionet.de>.
http://wicket.apache.org/docs/1.4/org/apache/wicket/markup/html/form/Form.html
-----Ursprüngliche Nachricht-----
Von: vov [mailto:vov-86@mail.ru]
Gesendet: Freitag, 18. Juni 2010 12:11
An: users@wicket.apache.org
Betreff: AJAX Button does not submit form if RequiredTextField is empty
Form<Void> form = new Form<Void>("form");
form.add(new RequiredTextField<String>("filed"));
final TextField<String> textField;
form.add(textField = new TextField<String>("filed2", new
Model<String>()));
form.add(new AjaxButton("button")
{
@Override
protected void onSubmit(AjaxRequestTarget target,
@SuppressWarnings("hiding") Form<?> form)
{
System.out.println("Test." + textField.getConvertedInput());
System.out.println("Test." + textField.getModelObject());
}
});
In case if "filed" is empty than onSubmit() method does not call after
submitting button.
I can find only one solution - to override process() and onValidate()
methods of form as fallows:
Form<Void> form = new Form<Void>("form")
{
@Override
public void process(IFormSubmittingComponent submittingComponent)
{
if ("button".equals(submittingComponent.getInputName()))
{
getApplication().getSessionStore().setAttribute(getRequest(),
"button", true);
}
super.process(submittingComponent);
}
@SuppressWarnings("unchecked")
@Override
protected void onValidate()
{
if (getApplication().getSessionStore().getAttribute(getRequest(),
"unvalidate") != null
&& (Boolean)
getApplication().getSessionStore().getAttribute(getRequest(), "unvalidate"))
{
getApplication().getSessionStore().removeAttribute(getRequest(),
"button");
Session.get().getFeedbackMessages().clear();
return;
}
}
};
...but IMHO it's not good:)
What is the correct way to solve this problem?
thanks in advance
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/AJAX-Button-does-not-submit-form-if-RequiredTextField-is-empty-tp2259981p2259981.html
Sent from the Wicket - User 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