将操作方法名称作为参数传递给Facelets组件网络 [英] Passing action method names as arguments to facelets componenets
问题描述
我正在调用模板并传递如下参数:
I am calling a template and am passing in parameters like below:
<ui:include src="WEB-INF/Subviews/ProductEdit.xhtml">
<ui:param name="items" value="#{produtList}"></ui:param>
<ui:param name="itemToEdit" value="#{productToEdit}"></ui:param>
</ui:include>
在ProductEdit.xhtml中,我有类似
and in the ProductEdit.xhtml, I have something like
<ui:repeat value="#{items}" var="item">
<tr>
...
...
<td style="text-align: center">
<h:commandLink style="cssGenericColumn" action="#{productEditAction}">
<f:setPropertyActionListener target="#{itemToEdit}" value="#{item}"/>
</h:commandLink>
</td>
<tr>
</ui:repeat>
效果很好.
我现在想在ProductEdit.xhtml中对#{productEditAction}进行参数化,所以我做了以下
I now want to parameterize the #{productEditAction} in the ProductEdit.xhtml and so I did the following
<ui:include src="WEB-INF/Subviews/ProductEdit.xhtml">
<ui:param name="items" value="#{produtList}"></ui:param>
<ui:param name="itemToEdit" value="#{productToEdit}"></ui:param>
<ui:param name="itemEditAction" value="#{productEditAction}"></ui:param>
</ui:include>
在第一页中,然后在ProductEdit.xhtml中,我
in the first page and then in ProductEdit.xhtml I do
<ui:repeat value="#{items}" var="item">
<tr>
...
...
<td style="text-align: center">
<h:commandLink style="cssGenericColumn" action="#{itemEditAction}">
<f:setPropertyActionListener target="#{itemToEdit}" value="#{item}"/>
</h:commandLink>
</td>
<tr>
</ui:repeat>
并且由于以下错误而失败
and this fails on the following error
javax.faces.el.EvaluationException: /WEB-INF/Subviews/ProductEdit.xhtml @45,89 action="#{itemEditAction}": Identity 'itemEditAction' does not reference a MethodExpression instance, returned type: java.lang.String
at com.sun.facelets.el.LegacyMethodBinding.invoke(LegacyMethodBinding.java: at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java: at javax.faces.component.UICommand.broadcast(UICommand.java:109)....
....
....
....
但是,如果操作绑定到模型对象,则此方法有效.像
This however works if the action bound to the model object. So something like
<h:commandLink style="cssGenericColumn" action="#{item.editAction}">
有什么想法吗?
推荐答案
将方法作为参数传递应采用以下方式:
Passing a method as a parameter should be done in this way:
itemBean="#{bean}"
itemEditAction="productEditAction"
,然后在您的组件中将它们放到gheter中:
and in your component you will put them togheter:
action="#{itemBean[itemEditAction]}"
这篇关于将操作方法名称作为参数传递给Facelets组件网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!