自定义标签在迭代时不能绑定多个变量?

发布于 2021-11-23 13:00:05 字数 6600 浏览 936 评论 4

@闲.大赋 你好,想跟你请教个问题版本beetl-core-2.0.13.jar:

原来写了自定义迭代标签,需要需要获取迭代的索引值,所有我在变量的里面添加一个bind方法绑定索引值。下面是自定义标签的源代码,

this.bind("zzzz",i);

上面就是绑定索引值的代码

/**
 * 用于遍历多个系统参数
 * @author Administrator
 *
 */
@BeetlName("param")
public class ParamTag extends BaseTag {
	

	public void render() {
		String key = String.valueOf(this.getAttributeValue("type"));
		if(key!=null){
			List<SysParam> sysParams = KgCacheKit.getSysParamsByType(key);
			for (int i = 0; i < sysParams.size(); i++) {
				this.bind(this.args[2].toString(),sysParams.get(i));
				this.bind("zzzz",i);
				this.doBodyRender();
			}
			
		}
	}
	
}



this.bind("zzzz",i);

这行报错

下面是错误信息

2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - >>错误:htmltagvar 位于68行 资源:/public/user/template/set_sign.html
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - tag执行抛错
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 65|					<div class="form-group">
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 66|						<label class="col-md-2 control-label required">指定页码</label>
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 67|						<div class="col-md-8">
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 68|							<#param type="sign.page" ; target>
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 69|								 <label class='radio-inline'><input type="radio" name="page" value="${target.code}" ${zzzz ==0?'checked'}> ${target.name} </label>
2014-11-25 18:08:02 625 [http-8089-5] [ERROR]  - 70|							</#param>
java.lang.RuntimeException
	at org.beetl.core.GeneralVarTagBinding.bind(GeneralVarTagBinding.java:105)
	at com.kg.core.beetl.tag.ParamTag.render(ParamTag.java:28)
	at org.beetl.ext.tag.HTMLTagVarBindingWrapper.render(HTMLTagVarBindingWrapper.java:47)
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:54)
	at org.beetl.core.statement.TagStatement.execute(TagStatement.java:87)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.engine.FastRuntimeEngine$FilterProgram.execute(FastRuntimeEngine.java:43)
	at org.beetl.core.Template.renderTo(Template.java:121)
	at org.beetl.core.Template.renderTo(Template.java:87)
	at com.jfinal.ext.beetl.MyWebRender.render(MyWebRender.java:64)
	at com.jfinal.ext.beetl.KgWebBeetlRender.render(KgWebBeetlRender.java:27)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:92)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
2014-11-25 18:08:02 640 [http-8089-5] [ERROR]  - /user/template/set_sign/1-20?q_templateid=ce0f209f9c714ead86e3945e718eb132
com.jfinal.render.RenderException: ERROR
	at com.jfinal.ext.beetl.KgWebBeetlRender.render(KgWebBeetlRender.java:31)
	at com.jfinal.core.ActionHandler.handle(ActionHandler.java:92)
	at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:72)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)
Caused by: ERROR
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:63)
	at org.beetl.core.statement.TagStatement.execute(TagStatement.java:87)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.engine.FastRuntimeEngine$FilterProgram.execute(FastRuntimeEngine.java:43)
	at org.beetl.core.Template.renderTo(Template.java:121)
	at org.beetl.core.Template.renderTo(Template.java:87)
	at com.jfinal.ext.beetl.MyWebRender.render(MyWebRender.java:64)
	at com.jfinal.ext.beetl.KgWebBeetlRender.render(KgWebBeetlRender.java:27)
	... 14 more
Caused by: java.lang.RuntimeException
	at org.beetl.core.GeneralVarTagBinding.bind(GeneralVarTagBinding.java:105)
	at com.kg.core.beetl.tag.ParamTag.render(ParamTag.java:28)
	at org.beetl.ext.tag.HTMLTagVarBindingWrapper.render(HTMLTagVarBindingWrapper.java:47)
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:54)
	... 21 more


页面的html代码如下

<#param type="sign.page" ; target>
								 <label class='radio-inline'><input type="radio" name="page" value="${target.code}" ${zzzz ==0?'checked'}> ${target.name} </label>
							</#param>



或者我迭代,如何像LP那样获取跌打的索引等信息

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

拍不死你 2021-11-29 17:40:02

引用来自“闲.大赋”的评论

补充:既可以按照名字绑定,也可以按照顺序绑定(这是推荐的方式),

你那个报错是因为代码里绑定了多个变量,但实际只申明了一个。 错误提示不是很清楚,2.1.2 版本即将改善此错误提示:比如

>>错误:htmltagvar 位于1行 资源:/org/beetl/core/lab/hello.txt
tag执行抛错
1|<#menu ;menu ,index>
2|</#menu>
java.lang.RuntimeException: 申明的绑定和代码里实际绑定不一致:试图绑定未申明的变量imenu
	at org.beetl.core.GeneralVarTagBinding.bind(GeneralVarTagBinding.java:106)
	at org.beetl.core.lab.TestGeneralVarTagBinding.render(TestGeneralVarTagBinding.java:32)
	at org.beetl.ext.tag.HTMLTagVarBindingWrapper.render(HTMLTagVarBindingWrapper.java:52)
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:54)
	at org.beetl.core.statement.TagStatement.execute(TagStatement.java:87)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.engine.FilterProgram.execute(FilterProgram.java:31)
	at org.beetl.core.Template.renderTo(Template.java:123)
	at org.beetl.core.Template.renderTo(Template.java:102)
	at org.beetl.core.lab.Test.main(Test.java:49)

清风夜微凉 2021-11-29 10:22:14

引用来自“闲.大赋”的评论

补充:既可以按照名字绑定,也可以按照顺序绑定(这是推荐的方式),

你那个报错是因为代码里绑定了多个变量,但实际只申明了一个。 错误提示不是很清楚,2.1.2 版本即将改善此错误提示:比如

>>错误:htmltagvar 位于1行 资源:/org/beetl/core/lab/hello.txt
tag执行抛错
1|<#menu ;menu ,index>
2|</#menu>
java.lang.RuntimeException: 申明的绑定和代码里实际绑定不一致:试图绑定未申明的变量imenu
	at org.beetl.core.GeneralVarTagBinding.bind(GeneralVarTagBinding.java:106)
	at org.beetl.core.lab.TestGeneralVarTagBinding.render(TestGeneralVarTagBinding.java:32)
	at org.beetl.ext.tag.HTMLTagVarBindingWrapper.render(HTMLTagVarBindingWrapper.java:52)
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:54)
	at org.beetl.core.statement.TagStatement.execute(TagStatement.java:87)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.engine.FilterProgram.execute(FilterProgram.java:31)
	at org.beetl.core.Template.renderTo(Template.java:123)
	at org.beetl.core.Template.renderTo(Template.java:102)
	at org.beetl.core.lab.Test.main(Test.java:49)

孤独患者 2021-11-29 03:06:37

补充:既可以按照名字绑定,也可以按照顺序绑定(这是推荐的方式),

你那个报错是因为代码里绑定了多个变量,但实际只申明了一个。 错误提示不是很清楚,2.1.2 版本即将改善此错误提示:比如

>>错误:htmltagvar 位于1行 资源:/org/beetl/core/lab/hello.txt
tag执行抛错
1|<#menu ;menu ,index>
2|</#menu>
java.lang.RuntimeException: 申明的绑定和代码里实际绑定不一致:试图绑定未申明的变量imenu
	at org.beetl.core.GeneralVarTagBinding.bind(GeneralVarTagBinding.java:106)
	at org.beetl.core.lab.TestGeneralVarTagBinding.render(TestGeneralVarTagBinding.java:32)
	at org.beetl.ext.tag.HTMLTagVarBindingWrapper.render(HTMLTagVarBindingWrapper.java:52)
	at org.beetl.core.statement.TagVarBindingStatement.runTag(TagVarBindingStatement.java:54)
	at org.beetl.core.statement.TagStatement.execute(TagStatement.java:87)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.engine.FilterProgram.execute(FilterProgram.java:31)
	at org.beetl.core.Template.renderTo(Template.java:123)
	at org.beetl.core.Template.renderTo(Template.java:102)
	at org.beetl.core.lab.Test.main(Test.java:49)

卸妝后依然美 2021-11-25 23:19:19
@BeetlName("param")
public class ParamTag extends BaseTag {
     
 
    public void render() {
        String key = String.valueOf(this.getAttributeValue("type"));
        if(key!=null){
            List<SysParam> sysParams = KgCacheKit.getSysParamsByType(key);
            for (int i = 0; i < sysParams.size(); i++) {
                //按照顺序绑定俩个变量
                this.binds(sysParams.get(i),i)
                this.doBodyRender();
            }
             
        }
    }

在标签里:

<#param type="sign.page" ; target,index>
                                 <label class='radio-inline'><input type="radio" name="page" value="${target.code}" ${index==0?'checked'}> ${target.name} </label>
                            </#param>

具体可以参考文档: http://ibeetl.com/guide/   2.22.绑定变量的HTML标签

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文