Java 自由标记:freemarker.core.InvalidReferenceException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19924816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Free Marker: freemarker.core.InvalidReferenceException
提问by Pathfinder92
I use freemarker templates and i have given the code within the ftl file below.
我使用 freemarker 模板,并在下面的 ftl 文件中提供了代码。
<#if (actionErrors?exists && actionErrors?size > 0)>
<ul>
<#list actionErrors as error>
<li><span<#rt/>
<#if parameters.cssClass?exists>
class="${parameters.cssClass?html}"<#rt/>
</#if>
<#if parameters.cssStyle?exists>
style="${parameters.cssStyle?html}"<#rt/>
</#if>
>${error}</span></li>
</#list>
</ul>
</#if>
The above code gives the following error.
上面的代码给出了以下错误。
freemarker.core.InvalidReferenceException: Expression error is undefined on line 33
freemarker.core.InvalidReferenceException:第 33 行未定义表达式错误
I wrapped the ${error} with <#if error.value??> and tried again. Still it gave the same issue. Then i used the ${error.value!'N/A'} as mentioned here. Still it didn't resolve the issue. Please help me with this.
我用 <#if error.value??> 包裹了 ${error} 并再次尝试。它仍然给出了同样的问题。然后我使用了这里提到的 ${error.value!'N/A'} 。仍然没有解决问题。请帮我解决一下这个。
Thank you in advance.
先感谢您。
Thank you.
谢谢你。
回答by Charles Forsythe
As already mentioned, the error
value appears not to have been set. When you do this:
如前所述,该error
值似乎尚未设置。当你这样做时:
${error.value!"Default"}
...you are providing a default in case the value
attribute of error
is not set. It still assumes that error
is set so that it can get the value
attribute off it. If you do this:
...如果未设置value
属性,您将提供默认值error
。它仍然假定error
已设置,以便它可以从中获取value
属性。如果你这样做:
${(error.value)!"Default"}
...the default will apply if eithererror
or error.value
is not set. The parentheses say "apply the default to the enclosed expression." If Freemarker encounters a missing value anywhere while parsing the enclosed expression, it applies the default.
...默认将适用,如果任一error
或者error.value
未设置。括号表示“将默认值应用于封闭的表达式”。如果 Freemarker 在解析封闭表达式时在任何地方遇到缺失值,它会应用默认值。
This also works with the ??
operator:
这也适用于??
运营商:
<#if (error.value)??>The entire expression error.value is valid</#if>