Java Code Examples for org.beetl.core.Template#dynamic()

The following examples show how to use org.beetl.core.Template#dynamic() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLTagSupportWrapper.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void callHtmlTag(String path)
{
	Template t = null;

	t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());

	t.binding(ctx.globalVar);
	t.dynamic(ctx.objectKeys);

	if (args.length == 2)
	{
		Map<String, Object> map = (Map<String, Object>) args[1];
		for (Entry<String, Object> entry : map.entrySet())
		{
			t.binding(entry.getKey(), entry.getValue());

		}
	}

	BodyContent bodyContent = super.getBodyContent();
	t.binding("tagBody", bodyContent);

	t.renderTo(ctx.byteWriter);
}
 
Example 2
Source File: LayoutTag.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render()
{
	if (args.length == 0 || args.length > 3)
	{
		throw new RuntimeException("参数错误,期望child,map");
	}
	String layoutFile = getRelResourceId();
	Template t = this.gt.getTemplate(layoutFile, this.ctx.getResourceId());

	t.binding(ctx.globalVar);
	t.dynamic(ctx.objectKeys);

	if (args.length >= 2)
	{
		Map<String, Object> map = (Map<String, Object>) args[1];
		for (Entry<String, Object> entry : map.entrySet())
		{
			t.binding(entry.getKey(), entry.getValue());
		}
	}

	BodyContent content = this.getBodyContent();
	if (args.length == 3)
	{

		t.binding((String) args[2], content);
	}
	else
	{
		t.binding(defaultLayoutName, content);
	}
	t.renderTo(ctx.byteWriter);

}
 
Example 3
Source File: IncludeTag.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void render()
{
	String resourceId = getRelResourceId();
	;

	Template t = gt.getTemplate(resourceId, this.ctx.getResourceId());
	//快速复制父模板的变量
	t.binding(this.ctx.globalVar);
	if (ctx.objectKeys != null && ctx.objectKeys.size() != 0)
	{
		t.dynamic(ctx.objectKeys);
	}

	if (this.args.length == 2)
	{
		Map<String, Object> map = (Map<String, Object>) this.args[1];
		for (Entry<String, Object> entry : map.entrySet())
		{
			Object value = entry.getValue();
			if (value instanceof Map || value instanceof Collection)
			{
				t.binding((String) entry.getKey(), value, true);
			}
			else
			{
				t.binding((String) entry.getKey(), value);
			}

		}

	}

	ByteWriter bw = ctx.byteWriter;
	t.renderTo(bw);

}
 
Example 4
Source File: HTMLTagSupportWrapper2.java    From beetl2.0 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
protected void callHtmlTag(String path) {
    Template t = null;

    t = gt.getHtmlFunctionOrTagTemplate(path, this.ctx.getResourceId());

    t.binding(ctx.globalVar);
    t.dynamic(ctx.objectKeys);

    if (args.length == 2) {
        Map<String, Object> map = (Map<String, Object>)args[1];
        for (Entry<String, Object> entry : map.entrySet()) {
            t.binding(entry.getKey(), entry.getValue());

        }
    }
    /*
       模板需要调用方法 与默认实现不同,并没有先渲染body体,而是延迟处理, 等待调用的时候在获取tag体内容
      
     */
    t.binding("tagBody", new Object() {
    	public String toString() {
    		try {
    			return HTMLTagSupportWrapper2.super.getBodyContent().toString();
    		}catch(BeetlException ex){
    			ex.inTagBody = true;
    			throw ex;
    		}
    		
    		
    	}
    });
    t.renderTo(ctx.byteWriter);
}