我正在调用模板并传入如下参数:
<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}">
有任何想法吗?