use of org.webpieces.router.impl.dto.RenderResponse in project webpieces by deanhiller.
the class ResponseProcessorAppError method createRenderResponse.
public XFuture<Void> createRenderResponse(MethodMeta meta, RenderImpl controllerResponse, ProxyStreamHandle handle) {
LoadedController loadedController = meta.getLoadedController();
String controllerName = loadedController.getControllerInstance().getClass().getName();
String methodName = loadedController.getControllerMethod().getName();
String relativeOrAbsolutePath = controllerResponse.getRelativeOrAbsolutePath();
if (relativeOrAbsolutePath == null) {
relativeOrAbsolutePath = methodName + ".html";
}
Map<String, Object> pageArgs = controllerResponse.getPageArgs();
RequestContext ctx = meta.getCtx();
// Add context as a page arg:
pageArgs.put("_context", ctx);
pageArgs.put("_session", ctx.getSession());
pageArgs.put("_flash", ctx.getFlash());
pageArgs.put("_appContext", ctx.getApplicationContext());
View view = new View(controllerName, methodName, relativeOrAbsolutePath);
RenderResponse resp = new RenderResponse(view, pageArgs, RouteType.INTERNAL_SERVER_ERROR);
return handle.sendRenderHtml(resp);
}
use of org.webpieces.router.impl.dto.RenderResponse in project webpieces by deanhiller.
the class ResponseProcessorHtml method createRenderResponse.
public XFuture<Void> createRenderResponse(MethodMeta meta, RenderImpl controllerResponse, ProxyStreamHandle handle) {
RequestContext ctx = meta.getCtx();
RouterRequest request = ctx.getRequest();
LoadedController loadedController = meta.getLoadedController();
Method method = loadedController.getControllerMethod();
// not broken)
if (HttpMethod.POST == request.method) {
throw new IllegalReturnValueException("Controller method='" + method + "' MUST follow the PRG " + "pattern(https://en.wikipedia.org/wiki/Post/Redirect/Get) so " + "users don't have a poor experience using your website with the browser back button. " + "This means on a POST request, you cannot return RenderHtml object and must return Redirects");
}
String controllerName = loadedController.getControllerInstance().getClass().getName();
String methodName = loadedController.getControllerMethod().getName();
String relativeOrAbsolutePath = controllerResponse.getRelativeOrAbsolutePath();
if (relativeOrAbsolutePath == null) {
relativeOrAbsolutePath = methodName + ".html";
}
Map<String, Object> pageArgs = controllerResponse.getPageArgs();
// Add context as a page arg:
pageArgs.put("_context", ctx);
pageArgs.put("_session", ctx.getSession());
pageArgs.put("_flash", ctx.getFlash());
pageArgs.put("_appContext", ctx.getApplicationContext());
View view = new View(controllerName, methodName, relativeOrAbsolutePath);
RenderResponse resp = new RenderResponse(view, pageArgs, RouteType.HTML);
return handle.sendRenderHtml(resp);
}
use of org.webpieces.router.impl.dto.RenderResponse in project webpieces by deanhiller.
the class ResponseProcessorNotFound method createRenderResponse.
public XFuture<Void> createRenderResponse(MethodMeta meta, RenderImpl controllerResponse, ProxyStreamHandle handle) {
LoadedController loadedController = meta.getLoadedController();
String controllerName = loadedController.getControllerInstance().getClass().getName();
String methodName = loadedController.getControllerMethod().getName();
String relativeOrAbsolutePath = controllerResponse.getRelativeOrAbsolutePath();
if (relativeOrAbsolutePath == null) {
relativeOrAbsolutePath = methodName + ".html";
}
Map<String, Object> pageArgs = controllerResponse.getPageArgs();
RequestContext ctx = meta.getCtx();
// Add context as a page arg:
pageArgs.put("_context", ctx);
pageArgs.put("_session", ctx.getSession());
pageArgs.put("_flash", ctx.getFlash());
pageArgs.put("_appContext", ctx.getApplicationContext());
View view = new View(controllerName, methodName, relativeOrAbsolutePath);
RenderResponse resp = new RenderResponse(view, pageArgs, RouteType.NOT_FOUND);
return handle.sendRenderHtml(resp);
}
Aggregations