gpt4 book ai didi

jsf - 已淘汰的Facelets代码仍会调用#{bean.action()}之类的EL表达式,并在#{bean.action}上导致javax.el.PropertyNotFoundException

转载 作者:行者123 更新时间:2023-12-04 09:36:09 24 4
gpt4 key购买 nike

我的Facelet中有以下代码段:

<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> -->

然后会引发以下异常:
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)

当我如下更改带有括号的方法表达式时,
<!--        <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)
...

因此,它将在注释块(可通过 CommentInstruction识别)中评估EL。注释块被视为模板文本。默认情况下,Facelets还会评估模板文本中的EL #{}。就像您在编写没有任何JSF标签的 <p>#{screenShotBean.takeScreenshot}</p>一样。

您有几种选择:
  • 完全删除注释块。
  • 在注释中使用\前缀在注释中转义EL表达式
    \#{screenShotBean.takeScreenshot}

    这样就不会对其进行评估。
  • 将整个注释块包装在 <ui:remove> 中,以便它不会出现在组件树中(也不出现在生成的HTML输出中)。
  • 通过将以下上下文参数添加到web.xml中,禁用Facelets对的所有注释的解析:
    <context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
    </context-param>

    请注意,没有任何注释将以这种方式最终出现在生成的HTML输出中。
  • 关于jsf - 已淘汰的Facelets代码仍会调用#{bean.action()}之类的EL表达式,并在#{bean.action}上导致javax.el.PropertyNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14692560/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com