我正在调用一个模板,并传入如下参数:
<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中,我有类似于
的内容<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},因此我做了以下操作
<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我做
<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>
,这在以下错误
时失败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)....
....
....
....
但是,如果操作绑定到模型对象,则此操作有效。比如
<h:commandLink style="cssGenericColumn" action="#{item.editAction}">
任何想法?
将方法作为参数传递,应该这样做:
itemBean="#{bean}"
itemEditAction="productEditAction"
,在你的组件中你要把它们放在一起:
action="#{itemBean[itemEditAction]}"
也许ActionMapperTagHandler可以工作。