You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Vadimus <so...@gmail.com> on 2013/11/13 09:54:13 UTC
Wicket 6 reset Form fields
Hi everyone.
I use Wicket 6.11.0.
I designed my own component BaseDialog.
BaseDialog.java
/public class BaseDialog extends Panel {
private WebMarkupContainer dialogDiv;
private AbstractDefaultAjaxBehavior beforeOpen;
private IndicatingAjaxButton sbt;
private Form<Void> form;
private FeedbackPanel fpanel;
/**
*
*/
private static final long serialVersionUID = -7300515046330284598L;
@SuppressWarnings("serial")
public BaseDialog(String id) {
super(id);
this.dialogDiv = new TransparentWebMarkupContainer("myModal");
this.dialogDiv.setOutputMarkupId(true);
this.dialogDiv.setMarkupId("myModal");
this.add(dialogDiv);
form = new Form<Void>("dlgForm");
form.setOutputMarkupId(true);
form.setMarkupId("dlgForm");
dialogDiv.add(form);
TransparentWebMarkupContainer ch = new TransparentWebMarkupContainer(
"childContent");
ch.setMarkupId("childContent");
ch.setOutputMarkupId(true);
dialogDiv.add(ch);
ch.add(form);
this.sbt = new IndicatingAjaxButton("sbmtBtn", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
form.success("asdasdas");
target.add(fpanel);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
form.error("error");
target.add(fpanel);
}
};
fpanel = new FeedbackPanel("feedback");
fpanel.setOutputMarkupId(true);
form.add(fpanel);
form.setDefaultButton(this.sbt);
this.sbt.setMarkupId("sbmtBtn");
this.sbt.setOutputMarkupId(true);
this.sbt.setDefaultFormProcessing(true);
dialogDiv.add(this.sbt);
// form.add(this.sbt);
this.beforeOpen = new AbstractDefaultAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
OnBeforeOpen();
target.add(form);
}
};
this.add(this.beforeOpen);
}
public JsScope GetOpenDialogScope() {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("beforeOpenUrl", this.beforeOpen.getCallbackUrl());
parameters.put("dialogId", this.dialogDiv.getMarkupId());
return JsScope.quickScope("$.ajax({" + " async : false," + "url : '"
+ this.beforeOpen.getCallbackUrl() + "'}).done(function() {});"
+ "$('#" + this.dialogDiv.getMarkupId() + "').modal();"
);
}
protected void OnBeforeOpen() {
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
Bootstrap.renderHead(response);
}
}
/
BaseDialog.html
/<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div wicket:id="myModal" class="modal hide fade" tabindex="-1"
role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">X</button>
Modal header
</div>
<div wicket:id="childContent" class="modal-body container">
<form wicket:id="dlgForm">
<div wicket:id="feedback"></div>
<wicket:child />
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal"
aria-hidden="true">Close</button>
<button class="btn" wicket:id="sbmtBtn">Save changes</button>
</div>
</div>
</wicket:panel>
</body>
</html>/
Then I designed AddDepartmentDlg which inherits BaseDialog.
AddDepartmentDlg.java
/public class AddDepartmentDlg extends BaseDialog {
/**
*
*/
@SpringBean(name = "departmentService")
private IDepartmentService depSrv;
private TextField<String> name;
private TextField<String> descr;
private SchTree tree;
private static final long serialVersionUID = 1L;
public AddDepartmentDlg(String id) {
super(id);
this.name = new RequiredTextField<String>("depName");
this.name.setMarkupId("depName");
this.name.setOutputMarkupId(true);
this.descr = new TextField<String>("depDescr");
this.descr.setMarkupId("depDescr");
this.descr.setOutputMarkupId(true);
this.tree = new SchTree("departments", new DepartmentsModel(depSrv));
tree.setMarkupId("departments");
tree.setOutputMarkupId(true);
this.add(this.name);
this.add(this.descr);
this.add(tree);
}
@Override
protected void OnBeforeOpen() {
this.name.modelChanged();
this.descr.modelChanged();
}
}
/
AddDepartmentDlg.html
/<html xmlns:wicket="http://wicket.apache.org">
<head></head>
<body>
<div>
<wicket:extend>
<div class="row">
<div class="span1 ">Name:</div>
<div class="span5">
<input wicket:id="depName" type="text" />
</div>
</div>
<div class="row">
<div class="span1">Description:</div>
<div class="span5">
<input wicket:id="depDescr" type="text" />
</div>
</div>
<div class="row">
<div class="span1">Parent Department:</div>
<div class="span4">
<div style="border: 1px solid #888; border-radius: 3px;">
<div wicket:id="departments"
style="height: 150px; overflow: auto;"></div>
</div>
</div>
</div>
</wicket:extend>
</div>
</body>
</html>
/
When I Put AddDepartmentDlg on my page and show this dialog, wicket calls
AbstractDefaultAjaxBehavior "beforeOpen" in the BaseDialog component. In
this call I wold like to reset all filelds and components which are
surrounded by wicket:form tag.
But it does not happen.
What I have to do in oreder to get all needed fields reseted?
And second question.
One of the fields surrounded by the wicket:form tag is
RequiredTextField<String>("depName");
Even if I leave this field empty and press AjaxSubmitButton validation does
not happen and OnSubmit Method of AjaxSubmitButton is called , but as I have
understood some validation should have place and OnError method of
AjaxSubmitButton should be called.
Thanks in advance.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-6-reset-Form-fields-tp4662358.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 6 reset Form fields
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
Next time please use any paste bin service with syntax highlighting. It is
much easier to read the code than here.
On Wed, Nov 13, 2013 at 10:54 AM, Vadimus <so...@gmail.com> wrote:
> Hi everyone.
>
> I use Wicket 6.11.0.
>
> I designed my own component BaseDialog.
> BaseDialog.java
>
> /public class BaseDialog extends Panel {
>
> private WebMarkupContainer dialogDiv;
> private AbstractDefaultAjaxBehavior beforeOpen;
> private IndicatingAjaxButton sbt;
> private Form<Void> form;
> private FeedbackPanel fpanel;
>
> /**
> *
> */
> private static final long serialVersionUID = -7300515046330284598L;
>
> @SuppressWarnings("serial")
> public BaseDialog(String id) {
> super(id);
>
> this.dialogDiv = new
> TransparentWebMarkupContainer("myModal");
> this.dialogDiv.setOutputMarkupId(true);
> this.dialogDiv.setMarkupId("myModal");
>
> this.add(dialogDiv);
>
> form = new Form<Void>("dlgForm");
>
>
> form.setOutputMarkupId(true);
> form.setMarkupId("dlgForm");
>
> dialogDiv.add(form);
>
> TransparentWebMarkupContainer ch = new
> TransparentWebMarkupContainer(
> "childContent");
> ch.setMarkupId("childContent");
> ch.setOutputMarkupId(true);
> dialogDiv.add(ch);
> ch.add(form);
>
> this.sbt = new IndicatingAjaxButton("sbmtBtn", form) {
> @Override
> protected void onSubmit(AjaxRequestTarget target,
> Form<?> form) {
> form.success("asdasdas");
> target.add(fpanel);
> }
>
> @Override
> protected void onError(AjaxRequestTarget target,
> Form<?> form) {
> form.error("error");
> target.add(fpanel);
> }
>
> };
>
> fpanel = new FeedbackPanel("feedback");
> fpanel.setOutputMarkupId(true);
> form.add(fpanel);
>
> form.setDefaultButton(this.sbt);
>
> this.sbt.setMarkupId("sbmtBtn");
> this.sbt.setOutputMarkupId(true);
> this.sbt.setDefaultFormProcessing(true);
>
> dialogDiv.add(this.sbt);
> // form.add(this.sbt);
>
> this.beforeOpen = new AbstractDefaultAjaxBehavior() {
>
> @Override
> protected void respond(AjaxRequestTarget target) {
> OnBeforeOpen();
> target.add(form);
> }
> };
>
> this.add(this.beforeOpen);
>
> }
>
> public JsScope GetOpenDialogScope() {
>
> Map<String, Object> parameters = new HashMap<String,
> Object>();
> parameters.put("beforeOpenUrl",
> this.beforeOpen.getCallbackUrl());
> parameters.put("dialogId", this.dialogDiv.getMarkupId());
>
> return JsScope.quickScope("$.ajax({" + " async : false," +
> "url : '"
> + this.beforeOpen.getCallbackUrl() +
> "'}).done(function() {});"
> + "$('#" + this.dialogDiv.getMarkupId() +
> "').modal();"
>
> );
> }
>
> protected void OnBeforeOpen() {
>
> }
>
> @Override
> public void renderHead(IHeaderResponse response) {
> super.renderHead(response);
> Bootstrap.renderHead(response);
> }
> }
> /
>
> BaseDialog.html
> /<html xmlns:wicket="http://wicket.apache.org">
> <body>
> <wicket:panel>
> <div wicket:id="myModal" class="modal hide fade"
> tabindex="-1"
> role="dialog" aria-labelledby="myModalLabel"
> aria-hidden="true">
> <div class="modal-header">
> <button type="button" class="close"
> data-dismiss="modal"
> aria-hidden="true">X</button>
>
> Modal header
>
> </div>
> <div wicket:id="childContent" class="modal-body
> container">
> <form wicket:id="dlgForm">
> <div wicket:id="feedback"></div>
> <wicket:child />
> </form>
> </div>
> <div class="modal-footer">
> <button class="btn" data-dismiss="modal"
> aria-hidden="true">Close</button>
> <button class="btn"
> wicket:id="sbmtBtn">Save changes</button>
> </div>
> </div>
> </wicket:panel>
> </body>
> </html>/
>
> Then I designed AddDepartmentDlg which inherits BaseDialog.
>
> AddDepartmentDlg.java
>
> /public class AddDepartmentDlg extends BaseDialog {
>
> /**
> *
> */
>
> @SpringBean(name = "departmentService")
> private IDepartmentService depSrv;
> private TextField<String> name;
> private TextField<String> descr;
> private SchTree tree;
>
>
> private static final long serialVersionUID = 1L;
>
> public AddDepartmentDlg(String id) {
> super(id);
>
> this.name = new RequiredTextField<String>("depName");
> this.name.setMarkupId("depName");
> this.name.setOutputMarkupId(true);
>
> this.descr = new TextField<String>("depDescr");
> this.descr.setMarkupId("depDescr");
> this.descr.setOutputMarkupId(true);
>
> this.tree = new SchTree("departments", new
> DepartmentsModel(depSrv));
> tree.setMarkupId("departments");
> tree.setOutputMarkupId(true);
> this.add(this.name);
> this.add(this.descr);
> this.add(tree);
> }
>
> @Override
> protected void OnBeforeOpen() {
>
> this.name.modelChanged();
> this.descr.modelChanged();
>
To reset I'd do:
this.name.setModelObject(""); // or whatever is considered as a default
value for name
// same for descr
> }
>
> }
> /
>
> AddDepartmentDlg.html
> /<html xmlns:wicket="http://wicket.apache.org">
> <head></head>
> <body>
> <div>
> <wicket:extend>
> <div class="row">
> <div class="span1 ">Name:</div>
> <div class="span5">
> <input wicket:id="depName"
> type="text" />
> </div>
> </div>
> <div class="row">
> <div class="span1">Description:</div>
> <div class="span5">
> <input wicket:id="depDescr"
> type="text" />
> </div>
> </div>
> <div class="row">
> <div class="span1">Parent Department:</div>
> <div class="span4">
> <div style="border: 1px solid
> #888; border-radius: 3px;">
> <div
> wicket:id="departments"
> style="height:
> 150px; overflow: auto;"></div>
> </div>
> </div>
> </div>
> </wicket:extend>
> </div>
> </body>
> </html>
> /
>
> When I Put AddDepartmentDlg on my page and show this dialog, wicket calls
> AbstractDefaultAjaxBehavior "beforeOpen" in the BaseDialog component. In
> this call I wold like to reset all filelds and components which are
> surrounded by wicket:form tag.
>
There is no such thing like <wicket:form>.
>
> But it does not happen.
> What I have to do in oreder to get all needed fields reseted?
>
Reset the model object as I suggested above and add the modified form
components to the AjaxRequestTarget to be re-rendered with their new values.
>
> And second question.
> One of the fields surrounded by the wicket:form tag is
> RequiredTextField<String>("depName");
> Even if I leave this field empty and press AjaxSubmitButton validation does
> not happen and OnSubmit Method of AjaxSubmitButton is called , but as I
> have
> understood some validation should have place and OnError method of
> AjaxSubmitButton should be called.
>
Put a breakpoint
at org.apache.wicket.markup.html.form.FormComponent#checkRequired and see
what happens.
>
> Thanks in advance.
>
>
>
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-6-reset-Form-fields-tp4662358.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
>
>