主题:HTML自定义标签 要在自定义标签外使用绑定变量 遇到的问题

float 2019年11月15日 54

我自定义标签的功能是 声明当前页面的全局变量

<FT:set data="${@contextKit.getFragment(depTable)}" export="fg" />

然后我把初始化参数 HTML_TAG_BINDING_ATTRIBUTE 设置为 var,export 后所有使用var 的自定义标签出了问题: 

不允许var关键出现在这里:'htmltag('forEach',{data:(method.evalutions),var

跟官方文档描述的稍有些出入, 无论Tag实现类如何往环境的参数容器里加值,渲染的时候都会提示没有声明该变量, 所以想请教一下,如何自定义HTML标签能在标签外部使用绑定的变量!!!!!! 谢谢

joelli 2019年11月15日

把配置贴一下,错误信息全贴出来吧!另外,实在不行,可以

@ var temp = null;
<FT:set data="${@contextKit.getFragment(depTable)}" var="fg" >
temp =null;
</FT:set>
float 2019年11月15日
>>03:17:02:语法错误(PARSER_VIABLE_ERROR):var 位于8行 资源:
    ${@method.annotations.render()}
    ${method.packageModiferSymbol} ${method.classType} ${method.name}(Model model, ${beanVo.name} view){
        if(view.${bean.pk.getter}!=null){
           ${bean.name} bean = ${service.selfInstanceName}.getById(view.${bean.pk.getter});
           model.addAttribute("bean",bean == null ? view : bean);
        }
				<FT:forEach data="${method.evalutions}" var="elt">
            <FT:choose>
              <FT:when test="${elt.evaluation.isEnumRelation}">
              model.addAttribute("${elt.evaluation.callObjName}",${elt.evaluation.orgin.name}.values());
              </FT:when>
              <FT:otherwise>
              model.addAttribute("${elt.evaluation.callObjName}",${elt.evaluation.orgin.service.selfInstanceName}.list());
              </FT:otherwise>
            </FT:choose>
        </FT:forEach>
        return "${@renderKit.uri(bean.selfInstanceName,viewAddName)}";
    }
不允许var关键出现在这里:'htmltag('forEach',{data:(method.evalutions),var'
5|           ${bean.name} bean = ${service.selfInstanceName}.getById(view.${bean.pk.getter});
6|           model.addAttribute("bean",bean == null ? view : bean);
7|        }
8|				<FT:forEach data="${method.evalutions}" var="elt">
9|            <FT:choose>
10|              <FT:when test="${elt.evaluation.isEnumRelation}">
11|              model.addAttribute("${elt.evaluation.callObjName}",${elt.evaluation.orgin.name}.values());
org.antlr.v4.runtime.NoViableAltException
	at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:1567)
	at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:491)
	at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:412)
	at org.beetl.core.parser.BeetlParser.statement(BeetlParser.java:376)
	at org.beetl.core.parser.BeetlParser.prog(BeetlParser.java:121)
	at org.beetl.core.engine.DefaultTemplateEngine.createProgram(DefaultTemplateEngine.java:56)
	at org.beetl.core.GroupTemplate.loadTemplate(GroupTemplate.java:669)
	at org.beetl.core.GroupTemplate.getTemplateByLoader(GroupTemplate.java:595)
	at org.beetl.core.GroupTemplate.getTemplate(GroupTemplate.java:559)
	at cn.ifloat.brick.generator.tookit.TemplateKit.get(TemplateKit.java:53)
	at cn.ifloat.brick.generator.vars.BMethod.render(BMethod.java:65)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at org.beetl.core.om.ObjectUtil.invoke(ObjectUtil.java:552)
	at org.beetl.core.statement.NativeCallExpression.evaluate(NativeCallExpression.java:186)
	at org.beetl.core.statement.PlaceholderST.execute(PlaceholderST.java:34)
	at org.beetl.core.statement.Program.execute(Program.java:70)
	at org.beetl.core.Template.renderTo(Template.java:136)
	at org.beetl.core.Template.renderTo(Template.java:102)
	at cn.ifloat.brick.generator.renders.ControllerRenderExecution.executionRender(ControllerRenderExecution.java:32)
	at cn.ifloat.brick.generator.renders.ViewRenderExecution.executionRender(ViewRenderExecution.java:25)
	at cn.ifloat.brick.generator.renders.EnumRenderExecution.executionRender(EnumRenderExecution.java:47)
	at cn.ifloat.brick.generator.renders.OtherSourceRenderExecution.executionRender(OtherSourceRenderExecution.java:34)
	at cn.ifloat.brick.generator.renders.RenderExecution.executionRenders(RenderExecution.java:34)
	at cn.ifloat.brick.generator.renders.EnumRenderExecution.executionRenders(EnumRenderExecution.java:42)
	at cn.ifloat.brick.generator.renders.OtherSourceRenderExecution.executionRenders(OtherSourceRenderExecution.java:60)
	at cn.ifloat.brick.generator.tasks.GeneratorTask.run(GeneratorTask.java:57)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
float 2019年11月15日

WX20191115-155008.png