Search in sources :

Example 6 with WebRender

use of org.beetl.ext.web.WebRender in project beetl2.0 by javamonkey.

the class ServletGroupTemplate method render.

public void render(String child, HttpServletRequest request, HttpServletResponse response) {
    WebRender render = new WebRender(groupTemplate);
    render.render(child, request, response);
}
Also used : WebRender(org.beetl.ext.web.WebRender)

Example 7 with WebRender

use of org.beetl.ext.web.WebRender in project beetl2.0 by javamonkey.

the class BeetlSpringView method renderMergedTemplateModel.

/* ----- ----- ----- ----- 实现方法 ----- ----- ----- ----- */
/**
 * 渲染指定视图
 *
 * @param model
 * @param request
 * @param response
 * @throws NoSuchBeanDefinitionException
 *             如果未设置GroupTemplate,且Spring上下文中也没有唯一的GroupTemplate bean
 * @throws NoUniqueBeanDefinitionException
 *             如果未设置GroupTemplate,且Spring上下文中有多个GroupTemplate bean
 */
@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws NoSuchBeanDefinitionException, NoUniqueBeanDefinitionException {
    // 如果未指定groupTemplate,取上下文中唯一的GroupTemplate对象
    if (groupTemplate == null) {
        groupTemplate = getApplicationContext().getBean(GroupTemplate.class);
    }
    // 渲染方法
    WebRender render = new WebRender(groupTemplate) {

        @Override
        protected void modifyTemplate(Template template, String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
            Map<?, ?> model = (Map<?, ?>) args[0];
            for (Entry<?, ?> entry : model.entrySet()) {
                String name = (String) entry.getKey();
                Object value = entry.getValue();
                template.binding(name, value);
            }
        }
    };
    String path = getUrl();
    render.render(path, request, response, model);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRender(org.beetl.ext.web.WebRender) HttpServletResponse(javax.servlet.http.HttpServletResponse) GroupTemplate(org.beetl.core.GroupTemplate) Map(java.util.Map) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template)

Example 8 with WebRender

use of org.beetl.ext.web.WebRender in project beetl2.0 by javamonkey.

the class Struts2BeetlActionResult method doExecute.

protected void doExecute(String locationArg, ActionInvocation invocation) throws Exception {
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    HttpServletResponse rsp = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    if (!locationArg.startsWith("/")) {
        String base = ResourceUtil.getResourceBase(req);
        locationArg = base + "/" + locationArg;
    }
    Object action = invocation.getAction();
    Map<String, Object> values = reflectionProvider.getBeanMap(action);
    rsp.setContentType(this.pContentType);
    WebRender render = new WebRender(groupTemplate) {

        protected void modifyTemplate(Template template, String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
            Map model = (Map) args[0];
            for (Object o : model.entrySet()) {
                Entry entry = (Entry) o;
                String name = (String) entry.getKey();
                Object value = entry.getValue();
                template.binding(name, value);
            }
        }
    };
    render.render(locationArg, req, rsp, values);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRender(org.beetl.ext.web.WebRender) Entry(java.util.Map.Entry) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Map(java.util.Map) Template(org.beetl.core.Template) GroupTemplate(org.beetl.core.GroupTemplate)

Example 9 with WebRender

use of org.beetl.ext.web.WebRender in project beetl2.0 by javamonkey.

the class BeetlActionResult method render.

@Override
public void render(ActionRequest actionRequest, Object resultValue) throws Exception {
    // TODO Auto-generated method stub
    WebRender render = new WebRender(groupTemplate);
    render.render((String) resultValue, actionRequest.getHttpServletRequest(), actionRequest.getHttpServletResponse());
}
Also used : WebRender(org.beetl.ext.web.WebRender)

Aggregations

WebRender (org.beetl.ext.web.WebRender)9 Map (java.util.Map)4 GroupTemplate (org.beetl.core.GroupTemplate)4 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 Template (org.beetl.core.Template)2 ScriptEvalError (org.beetl.core.exception.ScriptEvalError)2 ActionContext (com.opensymphony.xwork2.ActionContext)1 InputStream (java.io.InputStream)1 Entry (java.util.Map.Entry)1 Properties (java.util.Properties)1 ServletActionContext (org.apache.struts2.ServletActionContext)1 Configuration (org.beetl.core.Configuration)1 WebAppResourceLoader (org.beetl.core.resource.WebAppResourceLoader)1