Passing valueChangeListener method expression into tag file

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:48:36

问题


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}" />

With inside the tag file:

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


回答1:


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.

For JSF 2.x Facelets, this can be solved using OmniFaces <o:methodParam>.

<o:methodParam name="changeListenerMethod" value="#{changeListener}" />
<h:inputText valueChangeListener="#{changeListenerMethod}" />

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.

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.



来源:https://stackoverflow.com/questions/11140833/passing-valuechangelistener-method-expression-into-tag-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!