将操作方法​​名称作为参数传递给 Facelets 组件

发布于 2024-11-01 09:10:00 字数 2255 浏览 0 评论 0原文

我正在调用一个模板并传递如下参数:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信仰 2024-11-08 09:10:00

将方法作为参数传递应该以这种方式完成:

itemBean="#{bean}"
itemEditAction="productEditAction"

在您的组件中,您将把它们放在一起:

action="#{itemBean[itemEditAction]}"

Passing a method as a parameter should be done in this way:

itemBean="#{bean}"
itemEditAction="productEditAction"

and in your component you will put them togheter:

action="#{itemBean[itemEditAction]}"
ζ澈沫 2024-11-08 09:10:00

也许 ActionMapperTagHandler 会起作用。

Maybe the ActionMapperTagHandler would work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文