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