结合接缝 3 和 JSF2 复合组件 valueChangeListener 评估 El 表达式时出现问题

发布于 2024-12-02 10:01:47 字数 2777 浏览 2 评论 0原文

我有以下构造:

@Named    
public class SpecificAction extends BasicAction {

    public void calulateSomething(ValueChangeEvent event) {...}
}

}

@Named
public abstract class BasicAction {
     public void calculateSomething(ValueChangeEvent event) {...}
}

比视图:

文件: SpecificAction.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite/cc"
      xml:lang="de" lang="de">
    <ui:composition template="/BasicAction.xhtml">
        <ui:param name="basicAction" value="#{specificAction}" />
....
</ui:composition>

BasicAction.xhtml 包含我的复合组件:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite/cc"
      xmlns:gui="http://java.sun.com/jsf/composite/gui">
     <gui:inplaceInput id="name" valueChangeListener="#{basicAction.calculateSomething}" value=#{bean.name} />
</html>

复合组件:

<composite:interface>
    <composite:attribute name="value" />
    <composite:editableValueHolder name="Value"/>
    <composite:attribute name="valueChangeListener" targets="Value" />
</composite:interface>
<composite:implementation>
      <h:inputText id="Value" value="#{cc.attrs.value}" onblur="handleBlur(this.id);" >
          <composite:insertChildren />
      </h:inputText>
</composite:implementation>

如果我运行我的创建,如果 valueChangeListener 的 el 是“specifiedAction”,它会完美地工作。而且它在带有“basicAction”表达式的 basicAction.xhml 中工作得很好,只是使用复合组件我得到了那个有趣的异常:

[ExceptionHandlerFactory] Handling exception javax.faces.event.AbortProcessingException: javax.faces.event.AbortProcessingException: /BasicAction.xhtml @XX,XX valueChangeListener="#{basicAction.calculateSomething}": The class 'SpecificAction' does not have the property 'calculateSomething'.
    at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:157) [:2.1.3-FCS]
    at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134) [:2.1.3-FCS]
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) [:2.1.3-FCS]

任何想法,这可能是什么?
Seam 3 或 JSF2 框架中的错误或我这边的一些愚蠢错误?

感谢您的回答!

i have following construct:

@Named    
public class SpecificAction extends BasicAction {

    public void calulateSomething(ValueChangeEvent event) {...}
}

}

@Named
public abstract class BasicAction {
     public void calculateSomething(ValueChangeEvent event) {...}
}

Than the views:

File: SpecificAction.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite/cc"
      xml:lang="de" lang="de">
    <ui:composition template="/BasicAction.xhtml">
        <ui:param name="basicAction" value="#{specificAction}" />
....
</ui:composition>

The BasicAction.xhtml contains my Composite Component:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:cc="http://java.sun.com/jsf/composite/cc"
      xmlns:gui="http://java.sun.com/jsf/composite/gui">
     <gui:inplaceInput id="name" valueChangeListener="#{basicAction.calculateSomething}" value=#{bean.name} />
</html>

And the composite component:

<composite:interface>
    <composite:attribute name="value" />
    <composite:editableValueHolder name="Value"/>
    <composite:attribute name="valueChangeListener" targets="Value" />
</composite:interface>
<composite:implementation>
      <h:inputText id="Value" value="#{cc.attrs.value}" onblur="handleBlur(this.id);" >
          <composite:insertChildren />
      </h:inputText>
</composite:implementation>

If i run my creation it works perfectly if the el of the valueChangeListener is "specificAction". Also it works fine in the basicAction.xhml with the "basicAction" expression, just with the composite component i got that funny Exception:

[ExceptionHandlerFactory] Handling exception javax.faces.event.AbortProcessingException: javax.faces.event.AbortProcessingException: /BasicAction.xhtml @XX,XX valueChangeListener="#{basicAction.calculateSomething}": The class 'SpecificAction' does not have the property 'calculateSomething'.
    at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:157) [:2.1.3-FCS]
    at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134) [:2.1.3-FCS]
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) [:2.1.3-FCS]

Any Idea, what the hack could that be?.
Bug in Seam 3 or in JSF2 Framework or some stubid error on my side?

Thanks for answers!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吝吻 2024-12-09 10:01:47

这看起来与尝试将方法绑定传递到 Facelets 标记时遇到的错误类型完全相同。

由于 Facelets 中存在一些尴尬的设计错误,这永远不会起作用(仅与例外值有关)。

解决方案是将 bean 和方法名称作为单独的属性传递。然后最终使用数组样式寻址将它们组合起来:bean[methodName]。

也许这对你的情况也有帮助。

更新:

名为 OmniFaces 的新实用程序库有一个辅助标记,可让您使用方法表达式,而无需上述分解,查找 methodParam

This looks exactly like the kind of error you get when trying to pass a method binding into a Facelets tag.

Due to some awkward design error in Facelets, this never works (something to do with only excepting values).

The solution there is to pass the bean and name of the method as separate attributes. Then combine them eventually using array-style addressing: bean[methodName].

Maybe this also helps in your case.

Update:

A new utility library called OmniFaces has a helper tag that let's you use a method expression without the above mentioned breaking up, look for methodParam.

是伱的 2024-12-09 10:01:47

我对 EL 表达式解析为属性而不是方法有同样的问题,但仅限于 Mojarra 2.1.6 上的非托管 bean (@BalusC 由于使用托管 bean 可能没有遇到此问题)。

通过单独传递 bean 和方法来解决,如 Mike 提到的:

<composite:attribute name="valueChangeBean" required="true" />
<composite:attribute name="valueChangeMethod" required="true" />
...
<composite:implementation>
    <h:selectBooleanCheckbox
      valueChangeListener="#{cc.attrs.valueChangeBean[cc.attrs.valueChangeMethod]}"
      value="#{cc.attrs.isValue}"/>

使用页面:

<name:custom value="#{bean.val}"
             valueChangeBean="#{bean}"
             valueChangeMethod="onValChange" />

I had the same issue with the EL expression resolving as a property instead of a method, but only for unmanaged beans on Mojarra 2.1.6 ( @BalusC probably didn't encounter this due to using a managed bean ).

Resolved by passing the bean and method separately as mentioned by Mike:

<composite:attribute name="valueChangeBean" required="true" />
<composite:attribute name="valueChangeMethod" required="true" />
...
<composite:implementation>
    <h:selectBooleanCheckbox
      valueChangeListener="#{cc.attrs.valueChangeBean[cc.attrs.valueChangeMethod]}"
      value="#{cc.attrs.isValue}"/>

Using page:

<name:custom value="#{bean.val}"
             valueChangeBean="#{bean}"
             valueChangeMethod="onValChange" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文