Reputation: 117
I'm currently using three different forms, RadioChoice, DateField and DropDownChoice, in an application where the page reacts based on what the user picks from this form. The problem here is that when I submit the form that is using DateField and DropDownChoice, it does an refresh of the page and the choice from the RadioChoice is remembered but the default choice is shown instead. So my question is if it's either possible to clear the values and set them back to default after a refresh, or make the submit of DateField and DropDownChoice not refresh the page?
//RADIO CHOICE
RadioChoice<String> radioChoice = new RadioChoice<String>("radio", new PropertyModel<String>(this, "selectedRadio"),this.radioChoiceList);
radioChoice.add(new AjaxFormChoiceComponentUpdatingBehavior()
{
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target)
{
target.appendJavaScript(changeBaseLayerJS(Page.this.currentMap, Page.this.selectedRadio));
Page.this.currentMap = Page.this.selectedRadio;
}
});
Form<?> radioForm = new Form<Void>("radioForm");
add(radioForm);
radioForm.add(radioChoice);
//DATEFIELD AND DROPDOWNCHOICE
DateField fromDateField = new DateField("fromDateField", new PropertyModel<Date>(
this, "fromDate"));
DateField toDateField = new DateField("toDateField", new PropertyModel<Date>(
this, "toDate"));
DropDownChoice<String> idvNameMenu = new DropDownChoice<String>("idvNameMenu", new PropertyModel<String>(this, "idvTrackName"), individualChoiceList);
Form<?> trackingForm = new Form<Void>("trackingForm"){
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit()
{
//do stuff
}
};
Upvotes: 0
Views: 1144
Reputation: 17533
Normal (non-Ajax) form submit leads to full page repaint. Ajax form submit will repaint only the components you put into the AjaxRequestTarget
.
You can use form.add(new AjaxFormSubmittingBehavior() {...})
to do it with Ajax.
Or you can zero
-fy you model objects in onSubmit
:
@Override
protected void onSubmit()
{
// do stuff
// save in database
fromDate = null; // or = new Date();
toDate = null;
idvTrackName = "some good default value";
}
Upvotes: 3