将valueChangeListener方法表达式传递到标记文件中 [英] Passing valueChangeListener method expression into tag file
问题描述
我有一个<h:inputText>
,带有如下所示的事件侦听器:
I have a <h:inputText>
with an event listener like following:
<h:inputText valueChangeListener="#{myBean.handle}"/>
我想将其放在一个标签文件中,该文件将按以下方式使用:
I would like to put it in a tag file which is to be used as follows:
<my:itext changeListener="#{myBean.handle}" />
在标记文件中:
<h:inputText valueChangeListener="#{changeListener}" />
但是,它将它作为属性而不是作为侦听器方法进行评估.如何将侦听器方法传递到标记文件中?
However it's evaluating it as a property instead of as a listener method. How can I pass the listener method into a tag file?
推荐答案
您可以设计为不将方法表达式作为标记文件属性传递.基本上,您需要在标记文件中将ValueExpression
转换为MethodExpression
.
You can by design not pass method expressions as a tag file attribute. You basically need to convert the ValueExpression
to a MethodExpression
inside the tag file.
对于JSF 2.x Facelets,可以使用 OmniFaces <o:methodParam>
解决.
For JSF 2.x Facelets, this can be solved using OmniFaces <o:methodParam>
.
<o:methodParam name="changeListenerMethod" value="#{changeListener}" />
<h:inputText valueChangeListener="#{changeListenerMethod}" />
但是,对于旧的和不建议使用的Facelets 1.x或JSP 2.x,没有现有的解决方案. OmniFaces <o:methodParam>
是开源的,如果有必要,您应该能够为Facelets 1.x或JSP复制和更改它.
However, for old and deprecated Facelets 1.x or JSP 2.x there is no existing solution. The OmniFaces <o:methodParam>
is however open source, you should be able to copy and alter it for Facelets 1.x or JSP if necessary.
请注意,当您实际上已经在使用JSF 2.x时,也可以使用复合组件反而.这支持将方法表达式作为<cc:attribute method-signature>
传递.对于JSF 1.x,您也可以创建一个 real 定制组件,但这不仅仅只是一些XML.
Note that when you're actually already using JSF 2.x, you could also use a composite component instead. This supports passing method expressions as <cc:attribute method-signature>
. For JSF 1.x you can alternatively also create a real custom component, but that's a bit more work than just some XML.
这篇关于将valueChangeListener方法表达式传递到标记文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!