Search in sources :

Example 1 with RenderResponse

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);
}
Also used : LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext) RenderResponse(org.webpieces.router.impl.dto.RenderResponse) View(org.webpieces.router.impl.dto.View)

Example 2 with RenderResponse

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);
}
Also used : IllegalReturnValueException(org.webpieces.router.api.exceptions.IllegalReturnValueException) LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext) HttpMethod(org.webpieces.ctx.api.HttpMethod) Method(java.lang.reflect.Method) RenderResponse(org.webpieces.router.impl.dto.RenderResponse) View(org.webpieces.router.impl.dto.View) RouterRequest(org.webpieces.ctx.api.RouterRequest)

Example 3 with RenderResponse

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);
}
Also used : LoadedController(org.webpieces.router.impl.loader.LoadedController) RequestContext(org.webpieces.ctx.api.RequestContext) RenderResponse(org.webpieces.router.impl.dto.RenderResponse) View(org.webpieces.router.impl.dto.View)

Aggregations

RequestContext (org.webpieces.ctx.api.RequestContext)3 RenderResponse (org.webpieces.router.impl.dto.RenderResponse)3 View (org.webpieces.router.impl.dto.View)3 LoadedController (org.webpieces.router.impl.loader.LoadedController)3 Method (java.lang.reflect.Method)1 HttpMethod (org.webpieces.ctx.api.HttpMethod)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 IllegalReturnValueException (org.webpieces.router.api.exceptions.IllegalReturnValueException)1