You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by UPBrandon <bc...@up.com> on 2007/09/17 21:57:12 UTC

Refresh a page from an AjaxButton?

I'm writing a Wicket app that makes pretty heavy use of the Wicket-Extensions
ModalWindow to present what is basically a dialog box where the user can
enter information into a form.  The form on each "dialog box" is submitted
with an AjaxButton and each panel has a feedback panel that is refreshed to
show validation errors.  Everything works fine and right now I am just
closing a the dialog when the form is submitted successfully.  However, what
I would like to do is have the entire page reload to reflect whatever
changes the form submit may have caused.  I know that I could add certain
page elements to the AjaxButton's AjaxRequestTarget but the effect of the
dialog could be wide spread.  Is there any way to have an AjaxButton
"trigger" a complete non-Ajax page refresh?

-Brandon
-- 
View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12744000
Sent from the Wicket - User 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: Refresh a page from an AjaxButton?

Posted by hillj2 <Hi...@michigan.gov>.

UPBrandon wrote:
> 
> That seems to work.  I was trying to do exactly that earlier.  At the
> time, I couldn't seem to access the setResponsePage() method but I must
> have been doing something wrong.  For anyone who might be reading this
> later, I ended up calling setResponsePage(getPage() );
> 
> The only problem I am having now is that ModalWindow has an annoying "are
> you sure you want to navigate away from this page" JavaScript confirm
> since the modal window is open when the browser tries to move on.  Maybe
> there's something in the API to disable that warning...
> 
> 


I had this exact same problem but found my own way around it.  I'm using a
page for my modal window (so it probably would work a bit different if
you're using a Panel).  When I create my modal, I pass the parent page to
the constructor and store that as a member variable as well as the
ModalWindow object.  In the onSubmit handler of my ajax submit button I do:

if(/*Custom form vaidation*/) {

  /* Submit form data */

  parent.setSubmitted(true);  // this sets a variable in the parent class
that is initialized to false
  modalWindowObject.close(target);

} else {
  target.addComponent(ModalWindowForm.this);  // The allows you to see the
feedback panel inside the modal window, assuming it is inside the form
}


Then in the onClose handler of my modal window:

if(isSubmitted()) {  // Checks the member variable the modal window set on
submit (keeps whole page from refreshing if you close modal by other means)
  setResponsePage(ModalWindowParent.class);
}


The code may vary depending on your specific setup (particularly if you're
using a panel instead of a page for you modal window), but I think it should
be workable.  Not sure how it will work with wicket's built-in validators,
because I currently don't use those.

I spent quite some time trying to figure out how to do this, so I hope it
benefits others.  Seems to be the best way of handling a page modal which
has an internal feedback panel, which refreshes the whole page on a
successful submit, but not on a failure (or other close modal events).  It
also avoids the annoying popup, since you're directly calling the close
function.

Joel
-- 
View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12756667
Sent from the Wicket - User 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: Refresh a page from an AjaxButton?

Posted by UPBrandon <bc...@up.com>.
That seems to work.  I was trying to do exactly that earlier.  At the time, I
couldn't seem to access the setResponsePage() method but I must have been
doing something wrong.  For anyone who might be reading this later, I ended
up calling setResponsePage(getPage() );

The only problem I am having now is that ModalWindow has an annoying "are
you sure you want to navigate away from this page" JavaScript confirm since
the modal window is open when the browser tries to move on.  Maybe there's
something in the API to disable that warning...

Anyway, thanks for the help everyone.

-Brandon


John Ray wrote:
> 
> 
> UPBrandon wrote:
>> 
>> Is there any way to have an AjaxButton "trigger" a complete non-Ajax page
>> refresh?
>> 
> 
> Call setResponsePage() passing the page you want to be loaded after the
> AJAX call is complete. To refresh the current page simply pass in the
> current page i.e. "this".
> 
> 

-- 
View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12745497
Sent from the Wicket - User 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: Refresh a page from an AjaxButton?

Posted by John Ray <jo...@newonic.com>.

UPBrandon wrote:
> 
> Is there any way to have an AjaxButton "trigger" a complete non-Ajax page
> refresh?
> 

Call setResponsePage() passing the page you want to be loaded after the AJAX
call is complete. To refresh the current page simply pass in the current
page i.e. "this".

-- 
View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12744914
Sent from the Wicket - User 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: Refresh a page from an AjaxButton?

Posted by Matej Knopp <ma...@gmail.com>.
You can use setResponsePage(getPage()) to refresh the window from
Ajax(Submit)Button inside the window. The only problem is that you
can't close the window "regular" way then, so you'll get the
confirmation message.

To get rid of the message put this javascript somewhere in your page:
Wicket.Window.unloadConfirmation = false;

-Matej

On 9/17/07, UPBrandon <bc...@up.com> wrote:
>
> I thought about it but using ModalWindows makes things a little more
> complicated.  Using a regular button, the browser will navigate away and the
> modal window will be lost.  If there were no validation on the form inputs
> and the window always closed after the submit, that might not be a problem
> but it does create a problem if you want to do validation and have errors
> show up in that modal window.  Does that make sense at all?
>
> -Brandon
>
>
> David Bernard-2 wrote:
> >
> > Why not use a regular Button and the onSumit() method of the form if you
> > want to reload the page ?
> >
> > /david
> >
> > UPBrandon wrote:
> >> I'm writing a Wicket app that makes pretty heavy use of the
> >> Wicket-Extensions
> >> ModalWindow to present what is basically a dialog box where the user can
> >> enter information into a form.  The form on each "dialog box" is
> >> submitted
> >> with an AjaxButton and each panel has a feedback panel that is refreshed
> >> to
> >> show validation errors.  Everything works fine and right now I am just
> >> closing a the dialog when the form is submitted successfully.  However,
> >> what
> >> I would like to do is have the entire page reload to reflect whatever
> >> changes the form submit may have caused.  I know that I could add certain
> >> page elements to the AjaxButton's AjaxRequestTarget but the effect of the
> >> dialog could be wide spread.  Is there any way to have an AjaxButton
> >> "trigger" a complete non-Ajax page refresh?
> >>
> >> -Brandon
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12745341
> Sent from the Wicket - User 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
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Refresh a page from an AjaxButton?

Posted by UPBrandon <bc...@up.com>.
I thought about it but using ModalWindows makes things a little more
complicated.  Using a regular button, the browser will navigate away and the
modal window will be lost.  If there were no validation on the form inputs
and the window always closed after the submit, that might not be a problem
but it does create a problem if you want to do validation and have errors
show up in that modal window.  Does that make sense at all?

-Brandon


David Bernard-2 wrote:
> 
> Why not use a regular Button and the onSumit() method of the form if you
> want to reload the page ?
> 
> /david
> 
> UPBrandon wrote:
>> I'm writing a Wicket app that makes pretty heavy use of the
>> Wicket-Extensions
>> ModalWindow to present what is basically a dialog box where the user can
>> enter information into a form.  The form on each "dialog box" is
>> submitted
>> with an AjaxButton and each panel has a feedback panel that is refreshed
>> to
>> show validation errors.  Everything works fine and right now I am just
>> closing a the dialog when the form is submitted successfully.  However,
>> what
>> I would like to do is have the entire page reload to reflect whatever
>> changes the form submit may have caused.  I know that I could add certain
>> page elements to the AjaxButton's AjaxRequestTarget but the effect of the
>> dialog could be wide spread.  Is there any way to have an AjaxButton
>> "trigger" a complete non-Ajax page refresh?
>> 
>> -Brandon
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Refresh-a-page-from-an-AjaxButton--tf4469626.html#a12745341
Sent from the Wicket - User 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: Refresh a page from an AjaxButton?

Posted by David Bernard <dw...@free.fr>.
Why not use a regular Button and the onSumit() method of the form if you want to reload the page ?

/david

UPBrandon wrote:
> I'm writing a Wicket app that makes pretty heavy use of the Wicket-Extensions
> ModalWindow to present what is basically a dialog box where the user can
> enter information into a form.  The form on each "dialog box" is submitted
> with an AjaxButton and each panel has a feedback panel that is refreshed to
> show validation errors.  Everything works fine and right now I am just
> closing a the dialog when the form is submitted successfully.  However, what
> I would like to do is have the entire page reload to reflect whatever
> changes the form submit may have caused.  I know that I could add certain
> page elements to the AjaxButton's AjaxRequestTarget but the effect of the
> dialog could be wide spread.  Is there any way to have an AjaxButton
> "trigger" a complete non-Ajax page refresh?
> 
> -Brandon

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org