I have a modal window with form inside it. There are two way user can close the window: either by filling up correctly form and submit change, or clicking an “x” in top right corner.
Now I’m trying to do following thing:
When user sucesfully fills up the form and submit change, on parent page I’m trying to display (with jQuery) some information about success.
When user clicks an “x” I want the modal window to be closed without any additional info. However setWindowClosedCallback is not working as I expected. Take a look at my code, first I’m getting reference to modalWindow (I omitted some not interesting parts of the code like adding form inputs etc.):
public EditEmailForm( String id, final ModalWindow modalWindow,final User u )
{
super( id );
modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback()
{
private static final long serialVersionUID = 1L;
@Override
public void onClose(AjaxRequestTarget target)
{
//here some code doing jQuery magic for parent page
}
});
AjaxSubmitLink closeBtn = new AjaxCloseCancelBtn( "close-x", this );
add( new AjaxSubmitLink( "save", this )
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit( AjaxRequestTarget target, Form<?> form )
{
//here's user info change
}
@Override
protected void onError( AjaxRequestTarget target, Form<?> form )
{
target.add( feedbackPanel );
}
} );
add( closeBtn );
}
protected class AjaxCloseCancelBtn extends AjaxSubmitLink
{
private static final long serialVersionUID = 1L;
public AjaxCloseCancelBtn( String id, Form<?> form )
{
super( id, form );
setDefaultFormProcessing( false );
}
@Override
protected void onSubmit( AjaxRequestTarget target, Form<?> form )
{
modalWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback()
{
private static final long serialVersionUID = 1L;
@Override
public void onClose( AjaxRequestTarget arg0 )
{
}
});
// revert fields values
form.clearInput();
// close popup
modalWindow.close( target );
}
@Override
protected void onError( AjaxRequestTarget target, Form<?> form )
{
}
}
This code works 50% good, as it displays what I want on parent page, but it also does it when I hit an “x” even tho I’m trying to set new window close callback which is empty. Any solution how can I overcome this?
You need to call org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow.close(AjaxRequestTarget)