开发者社区> 问答> 正文

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

@闲.大赋 你好,想跟你请教个问题版本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那样获取跌打的索引等信息

展开
收起
爱吃鱼的程序员 2020-06-14 19:57:50 535 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    @BeetlName("param")publicclassParamTagextendsBaseTag{publicvoidrender(){Stringkey=String.valueOf(this.getAttributeValue("type"));if(key!=null){List<SysParam>sysParams=KgCacheKit.getSysParamsByType(key);for(inti=0;i<sysParams.size();i++){//按照顺序绑定俩个变量this.binds(sysParams.get(i),i)this.doBodyRender();}}}


    在标签里:


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




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


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

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

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



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

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

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

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



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

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

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

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



    2020-06-14 19:58:08
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
继承与功能组合 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多