将操作方法名称作为参数传递给 Facelets 组件
我正在调用一个模板并传递如下参数:
<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}">
什么想法吗?
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>
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>
which works fine.
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>
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}">
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将方法作为参数传递应该以这种方式完成:
在您的组件中,您将把它们放在一起:
Passing a method as a parameter should be done in this way:
and in your component you will put them togheter:
也许 ActionMapperTagHandler 会起作用。
Maybe the ActionMapperTagHandler would work.