use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class ModalWindow method getWindowOpenJavaScript.
/**
* Returns the javascript used to open the window. Subclass
* {@link #postProcessSettings(AppendingStringBuffer)} to modify the JavaScript if needed.
*
* See WICKET-12
*
* @return javascript that opens the window
*/
protected final String getWindowOpenJavaScript() {
JSONObject settings = new JSONObject();
settings.put("minWidth", getMinimalWidth());
settings.put("minHeight", getMinimalHeight());
settings.put("className", getCssClassName());
settings.put("width", getInitialWidth());
if ((isUseInitialHeight() == true) || (isCustomComponent() == false)) {
settings.put("height", getInitialHeight());
} else {
settings.put("height", (Object) null);
}
settings.put("resizable", isResizable());
if (isResizable() == false) {
settings.put("widthUnit", getWidthUnit());
settings.put("heightUnit", getHeightUnit());
}
if (isCustomComponent() == false) {
Page page = createPage();
if (page == null) {
throw new WicketRuntimeException("Error creating page for modal dialog.");
}
CharSequence pageUrl;
RequestCycle requestCycle = RequestCycle.get();
page.getSession().getPageManager().touchPage(page);
if (page.isPageStateless()) {
pageUrl = requestCycle.urlFor(page.getClass(), page.getPageParameters());
} else {
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
pageUrl = requestCycle.urlFor(handler);
}
settings.put("src", pageUrl);
} else {
settings.put("element", new JSONFunction("document.getElementById(\"" + getContentMarkupId() + "\")"));
}
if (getCookieName() != null) {
settings.put("cookieId", getCookieName());
}
String title = getTitle() != null ? getTitle().getObject() : null;
if (title != null) {
settings.put("title", getDefaultModelObjectAsString(title));
}
if (getMaskType() == MaskType.TRANSPARENT) {
settings.put("mask", "transparent");
} else if (getMaskType() == MaskType.SEMI_TRANSPARENT) {
settings.put("mask", "semi-transparent");
}
settings.put("autoSize", autoSize);
settings.put("unloadConfirmation", showUnloadConfirmation());
// set true if we set a windowclosedcallback
boolean haveCloseCallback = false;
// notification request
if (windowClosedCallback != null) {
WindowClosedBehavior behavior = getBehaviors(WindowClosedBehavior.class).get(0);
settings.put("onClose", new JSONFunction("function() { " + behavior.getCallbackScript() + " }"));
haveCloseCallback = true;
}
// close window property (thus cleaning the shown flag)
if ((closeButtonCallback != null) || (haveCloseCallback == false)) {
CloseButtonBehavior behavior = getBehaviors(CloseButtonBehavior.class).get(0);
settings.put("onCloseButton", new JSONFunction("function() { " + behavior.getCallbackScript() + "; return false; }"));
}
postProcessSettings(settings);
AppendingStringBuffer buffer = new AppendingStringBuffer(500);
buffer.append("var settings = ");
buffer.append(settings.toString());
buffer.append(";");
buffer.append(getShowJavaScript());
return buffer.toString();
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class RequestCycle method executeExceptionRequestHandler.
/**
* Execute a requestHandler for the given exception.
*
* @param exception
* @param retryCount
*/
private void executeExceptionRequestHandler(Exception exception, int retryCount) {
scheduleRequestHandlerAfterCurrent(null);
IRequestHandler handler = handleException(exception);
if (handler == null) {
log.error("Error during request processing. URL=" + request.getUrl(), exception);
return;
}
try {
listeners.onExceptionRequestHandlerResolved(this, handler, exception);
execute(handler);
} catch (Exception e) {
if (retryCount > 0) {
executeExceptionRequestHandler(exception, retryCount - 1);
} else {
log.error("Exception retry count exceeded", e);
}
}
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class RequestCycle method find.
/**
* Finds a IRequestHandler which is either the currently executing handler or is scheduled to be
* executed.
*
* @return the found IRequestHandler or {@link Optional#empty()}
*/
@SuppressWarnings("unchecked")
public <T extends IRequestHandler> Optional<T> find(final Class<T> type) {
if (type == null) {
return Optional.empty();
}
IRequestHandler result = getActiveRequestHandler();
if (type.isInstance(result)) {
return (Optional<T>) Optional.of(result);
}
result = getRequestHandlerScheduledAfterCurrent();
if (type.isInstance(result)) {
return (Optional<T>) Optional.of(result);
}
return Optional.empty();
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class RequestCycle method processRequest.
/**
* Processes the request.
*
* @return <code>true</code> if the request resolved to a Wicket request, <code>false</code>
* otherwise.
*/
public boolean processRequest() {
try {
set(this);
listeners.onBeginRequest(this);
onBeginRequest();
IRequestHandler handler = resolveRequestHandler();
if (handler == null) {
// Did not find any suitable handler, thus not executing the request
log.debug("No suitable handler found for URL {}, falling back to container to process this request", request.getUrl());
} else {
execute(handler);
return true;
}
} catch (Exception exception) {
executeExceptionRequestHandler(exception, getExceptionRetryCount());
return true;
} finally {
set(null);
}
return false;
}
use of org.apache.wicket.request.IRequestHandler in project wicket by apache.
the class RequestCycle method execute.
/**
* Execute a request handler and notify registered {@link IRequestCycleListener}s.
*
* @param handler
*/
private void execute(IRequestHandler handler) {
Args.notNull(handler, "handler");
while (handler != null) {
try {
listeners.onRequestHandlerResolved(this, handler);
IRequestHandler next = requestHandlerExecutor.execute(handler);
listeners.onRequestHandlerExecuted(this, handler);
handler = next;
} catch (RuntimeException e) {
ReplaceHandlerException replacer = Exceptions.findCause(e, ReplaceHandlerException.class);
if (replacer == null) {
throw e;
}
if (replacer.getRemoveScheduled()) {
requestHandlerExecutor.schedule(null);
}
handler = replacer.getReplacementRequestHandler();
}
}
}
Aggregations