问题描述
我在Facelet中有以下代码片段:
I've the following code snippet in my Facelet:
<h:commandLink id="cmdbtn">
<f:ajax event="click" execute="@form"
listener="#{screenShotBean.takeScreenshot}" />
</h:commandLink>
它可以正常工作,但是当我这样排斥它时,
It works fine, but when I outcomment it like this,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="@form" -->
<!-- listener="#{screenShotBean.takeScreenshot}" /> -->
<!-- </h:commandLink> -->
那么它会引发以下异常:
then it throws the following exception:
javax.el.PropertyNotFoundException: Property 'takeScreenshot' not found on type monstage.test.com.ScreenShotBean
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstValue.getValue(AstValue.java:169)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at com.sun.faces.facelets.el.ELText$ELTextVariable.toString(ELText.java:217)
at com.sun.faces.facelets.el.ELText$ELTextComposite.toString(ELText.java:157)
at com.sun.faces.facelets.compiler.CommentInstruction.write(CommentInstruction.java:77)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
当我用下面的括号修改方法表达式时,
When I change the method expression with parentheses as below,
<!-- <h:commandLink id="cmdbtn"> -->
<!-- <f:ajax event="click" execute="@form" -->
<!-- listener="#{screenShotBean.takeScreenshot()}" /> -->
<!-- </h:commandLink> -->
然后不抛出异常,但仍然被调用。
Then doesn't throw the exception, but it's still invoked.
这是如何引起的,我该如何解决呢?
How is this caused and how can I solve it?
推荐答案
以下是相关部分:
...
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 #{}
。就好像您在撰写< p>#{screenShotBean.takeScreenshot}< / p>
时没有任何JSF标记。
It's thus evaluating EL in a comment block (recognizable by CommentInstruction
). A comment block is considered as template text. Facelets evaluates by default also EL #{}
in template text. It's like as if you're writing <p>#{screenShotBean.takeScreenshot}</p>
without any JSF tag.
您有几个选项:
-
删除注释块。
Remove the comment block altogether.
在
\#{screenShotBean.takeScreenshot}
将整个评论区块包含在,以使其不会出现在
Wrap the entire comment block in <ui:remove>
so that it doesn't appear in the component tree (nor in the generated HTML output).
通过在Facelets中添加以下上下文参数,禁用对所有注释的解析 web.xml
:
Disable parsing of all comments by Facelets by adding the following context parameter to web.xml
:
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
请注意,生成的HTML输出中不会有任何注释。
Note that no one comment will end up in generated HTML output this way.
这篇关于Outcommented Facelets代码仍然调用EL表达式(如#{bean.action()}),并导致#{bean.action}上的javax.el.PropertyNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!