我下面有一个标签库
<po:create-option-entry var="optionEntry">
<li>${optionEntry.name}: <%=HtmlElementUtil.printAction(optionEntry.getAction())%></li>
</po:create-option-entry>
并且我收到了 optionEntry 未定义的异常。我已经见过一些类似的代码,但不记得如何连接它以使变量在 taglib 主体内可见。
ps.:taglib的定义如下
<tag>
<name>create-option-entry</name>
<tagclass>br.com.facilit.portlets.planooperativo.taglib.action_menu_entry.CreateOptionEntryTag</tagclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>var</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
最佳答案
我找到了解决我的问题的方法。我需要做的就是创建一个 CreateOptionEntryTei
<tag>
<name>create-option-entry</name>
<tagclass>pack.CreateOptionEntryTag</tagclass>
<teiclass>pack.CreateOptionEntryTei</teiclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>var</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
并像这样定义类
public class CreateOptionEntryTei extends TagExtraInfo {
public VariableInfo[] getVariableInfo(TagData data) {
String var = data.getAttributeString("var");
return new VariableInfo[] { new VariableInfo(var, OptionEntry.class.getName(), true, VariableInfo.NESTED), };
}
}
关于java - 通过 body 内的 taglib 定义变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21918762/