I was on my phone and didn't read that well the provided snippet, it should
work fine then ;)

__
Cedric Gatay (@Cedric_Gatay <http://twitter.com/Cedric_Gatay>)
http://code-troopers.com | http://www.bloggure.info | http://cedric.gatay.fr


On Mon, Nov 11, 2013 at 4:05 PM, Martin Grigorov <mgrigo...@apache.org>wrote:

> There is a difference between onunload and onbeforeunload. You can cancel
> the latter.
> You can make Ajax call only in onbeforeunload. And it has to be
> synchronous.
>
>
> On Mon, Nov 11, 2013 at 4:55 PM, Cedric Gatay <gata...@gmail.com> wrote:
>
> > AFAIK the browser won't issue a new server call (or will not process the
> > response) once the onunload event has been called so I doubt this will
> work
> > (using the web inspector of your browser will allow you to check whether
> or
> > not the call has been done)
> >
> > I second what Martin said, you need to add the JavaScript code to call
> the
> > server.
> > Le 11 nov. 2013 15:29, "Martin Grigorov" <mgrigo...@apache.org> a écrit
> :
> >
> > > respond() is the callback method that Wicket will notify.
> > > But you need to trigger an Ajax call first. This is done with the
> Wicket
> > > Ajax API: Wicket.Ajax.get(...).
> > >
> > > Just try with the line I've added in your JS code
> > >
> > >
> > > On Mon, Nov 11, 2013 at 4:04 PM, Daniela L <danigal...@gmail.com>
> wrote:
> > >
> > > > I thought adding respond was the ajax call to the server, am I wrong?
> > > > I didn't work much with ajax, i am sorry
> > > >
> > > >
> > > > 2013/11/11 Martin Grigorov <mgrigo...@apache.org>
> > > >
> > > > > Did you do what I suggested you ?
> > > > >
> > > > >
> > > > > On Mon, Nov 11, 2013 at 3:49 PM, Daniela L <danigal...@gmail.com>
> > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have tryed to change to AbstractDefaultAjaxBehavior like I
> > > described
> > > > > > below, but respond is never called. What am I doing wrong?
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > as far as I have understood this can only be achieved, if I
> > subclass
> > > > > > AbstractDefaultAjaxBehavior like this?
> > > > > >
> > > > > > public class PageExitWarningBehavior extends
> > > > AbstractDefaultAjaxBehavior
> > > > >  {
> > > > > > @Override
> > > > > >         protected void respond(AjaxRequestTarget target) {
> > > > > >
> > > > > > AppointmentSession.get().releaseSavedBlockedFreeCalendarEvent();
> > > > > >       }
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > You need to make an Ajax call to the server.
> > > > > >
> > > > > >
> > > > > > On Mon, Nov 11, 2013 at 2:10 PM, Daniela L <danigal...@gmail.com
> >
> > > > > > <danigal...@gmail.com><danigal...@gmail.com> <
> danigal...@gmail.com
> > >
> > > > > > wrote:
> > > > > >
> > > > > >
> > > > > > Hi,
> > > > > > this is my first question, so i hope I get everything right.
> > > > > >
> > > > > > I am trying to catch the event of the user closing the browser
> > window
> > > > in
> > > > > > wicket.
> > > > > >
> > > > > > I followed this example:
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://stackoverflow.com/questions/16527463/call-java-component-from-javascript-and-retreive-value
> > > > > >
> > > > > > and I managed to get the example working so the message is
> > displayed,
> > > > > but I
> > > > > > have no idea how to get the event triggered by the javascript
> > > function
> > > > in
> > > > > > wicket. I need this because when the user closes the browser
> > window I
> > > > > want
> > > > > > to update some data in my database.
> > > > > > Here is what I have tryed:
> > > > > >
> > > > > >
> > > > > >      RequiredTextField<String> myTextField = new
> > > > > > RequiredTextField<String>("myTextField");
> > > > > >      myTextField.setOutputMarkupPlaceholderTag(true);
> > > > > >      myTextField.add(new PageExitWarningBehavior(){
> > > > > >             @Override
> > > > > >             public void onEvent(Component component, IEvent<?>
> > event)
> > > > > >             {
> > > > > >                 //this isn't ever called
> > > > > >                 MySession.get().releaseBlockedDataFromDatabase();
> > > > > >                 }
> > > > > >         });
> > > > > >
> > > > > >     public class PageExitWarningBehavior extends Behavior  {
> > > > > >         @Override
> > > > > >         public void renderHead(Component component,
> IHeaderResponse
> > > > > > response) {
> > > > > >             super.renderHead(component, response);
> > > > > >                     response.render(new
> > > > > > OnDomReadyHeaderItem("window.onbeforeunload = function (e) {"
> > > > > >
> > > > > >
> > > > > >                       + "Wicket.Ajax.get({u:
> > '"+getCallbackUrl()+"',
> > > > > async:
> > > > > > false});"
> > > > > >
> > > > > >
> > > > > >                   + "var message = 'Your confirmation message
> goes
> > > > > > here.',"
> > > > > >
> > > > > >                       + "e = e || window.event;" + "if (e) {"
> > > > > >
> > > > > >                   + "e.returnValue = message;" + "}" + "return
> > > > message;"
> > > > > +
> > > > > > "};"));
> > > > > >         }
> > > > > >     }
> > > > > >
> > > > > > What am I missing? Thank you very much in advance
> > > > > >
> > > > >
> > > >
> > >
> >
>

Reply via email to