Hi, On Wed, Mar 12, 2014 at 1:15 PM, Daniela L <danigal...@gmail.com> wrote:
> Hi, > I am using a close browser behavior to clean up user data if the user > closes > the browser window. I also use a CheckBox to toggle the visibility of some > Textfields. Unfortunately the refresh through the click of the CheckBox > triggers the close browser > behavior. How can this be avoided? > Here is what I did (with wicket 6.12.0): > > > customerFirstName = new RequiredTextField<String>("customer.firstName"); > customerFirstName.setOutputMarkupPlaceholderTag(true); > closeBrowserBehavior = new AbstractDefaultAjaxBehavior() { > @Override > protected void respond(AjaxRequestTarget target) { > > AppointmentSession.get().releaseSavedBlockedFreeCalendarEvent(); > } > > @Override > public void renderHead(Component component, IHeaderResponse > response) { > super.renderHead(component, response); > response.render(new > OnDomReadyHeaderItem("window.onbeforeunload = > function (e) {" > + "if (!window.dontAsk) {" > + "Wicket.Ajax.get({u: > '"+getCallbackUrl()+"', async: false});" > + "var message = 'my message.'," > + "e = e || window.event;" + "if (e) {" > + "e.returnValue = message;" + "}}" + > "return message;" > + > "};")); > } > }; > customerFirstName.add(closeBrowserBehavior); > form.add(customerFirstName); > > createAccountCB = new CheckBox("createAccountCB", new > Model<Boolean>(createAccount)){ > @Override > protected void onSelectionChanged(Boolean newSelection) { > super.onSelectionChanged(newSelection); > createAccount = !createAccount; > } > > @Override > protected boolean wantOnSelectionChangedNotifications() > { > return true; > This uses non-Ajax way to submit the new selection. As you noted this leads to 'beforeunload' event being fired. You will have to use AjaxCheckBox or AjaxFormComponentUpdatingBehavior to avoid the page reload. > } > }; > form.add(createAccountCB); > > emailRepeat = new TextField<String>("emailRepeat", new > PropertyModel<String>(appointCalendar, customer.eMailAdress")){ > @Override > protected void onConfigure(){ > super.onConfigure(); > setVisibilityAllowed(createAccount); > } > } > }; > emailRepeat.setOutputMarkupPlaceholderTag(true); > form.add(emailRepeat): > > Thanks a lot in advance! > Best Regards > Daniela >