Jsf Outcommented Facelets代码仍然调用像#{bean.action()}这样的EL表达式,并导致#{bean.action}上的javax.EL.PropertyNotFoundException
我的Facelet中有以下代码片段:Jsf Outcommented Facelets代码仍然调用像#{bean.action()}这样的EL表达式,并导致#{bean.action}上的javax.EL.PropertyNotFoundException,jsf,comments,el,facelets,propertynotfoundexception,Jsf,Comments,El,Facelets,Propertynotfoundexception,我的Facelet中有以下代码片段: <h:commandLink id="cmdbtn"> <f:ajax event="click" execute="@form" listener="#{screenShotBean.takeScreenshot}" /> </h:commandLink> 当我更改带括号的方法表达式时,如下所示 <!-- <h:commandLink id="cmdbtn"&g
<h:commandLink id="cmdbtn">
<f:ajax event="click" execute="@form"
listener="#{screenShotBean.takeScreenshot}" />
</h:commandLink>
当我更改带括号的方法表达式时,如下所示
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="@form" -->
<!-- listener="#{screenShotBean.takeScreenshot()}" /> -->
<!-- </h:commandLink> -->
然后不会抛出异常,但仍会调用它
这是如何造成的,我如何解决它?仔细查看堆栈跟踪。以下是相关部分:
...
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
...
因此,它在注释块中计算EL(可通过CommentInstruction
识别)。注释块被视为模板文本。默认情况下,Facelets也会在模板文本中计算EL{}
。这就像是在编写没有任何JSF标记的{screenShotBean.takeScreenshot}
您有几种选择:
\
来转义注释中的EL表达式,如中所示
\#{screenShotBean.takeScreenshot}
这样他们就不会被评估了web.xml
,禁用Facelets对所有注释的解析:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
javax.faces.FACELETS\u跳过\u注释
真的
请注意,没有任何注释会以这种方式在生成的HTML输出中结束还可以使用上下文参数跳过web.xml中的注释
这是标准表:
javax.faces.FACELETS_SKIP_COMMENTS
除此之外,您还可以将属性rendered=“false”
添加到commandLink
中
如果您希望快速切换多个组件,您可能需要考虑在Bean中创建调试属性或使用项目阶段:
rendered="#{facesContext.application.projectStage == 'Development'}"
顺便说一句,我试图通过将所有以“/>”结尾的元素更改为完整的符号形式来解决此问题,但它不起作用。我使用了您建议的选项4并修复了propertyNotFoundException的问题。非常感谢。
javax.faces.FACELETS_SKIP_COMMENTS
rendered="#{facesContext.application.projectStage == 'Development'}"