【问题标题】:<a4j:commandLink> action not fired<a4j:commandLink> 操作未触发
【发布时间】:2014-04-20 06:21:30
【问题描述】:

我有一个&lt;a4j:commandLink&gt;,我需要在我的控制器上触发一个动作,

<h:form>
    <a4j:commandLink
        actionListener="#{controller.send(viewBean.id, cc.attrs.guid)}"
        onbegin="$.efc.busy($.messages.sending);"
        oncomplete="$.efc.busy('', true);">
        Send offer to this dealer
    </a4j:commandLink>
</h:form>

当我点击该链接时,onbegin javascript 被成功触发,但该操作从未被调用。这是我的控制器的操作:

public void send(String id, String guid) {
    if (id != null && guid != null) {
        ...
    }
}

我的 viewBean 是视图范围的,而 guid 来自组件...我在这里缺少什么?

编辑

如果我将链接更改为按钮,它可以工作......但我需要一个链接:

<a4j:commandButton
    action="#{controller.send(viewBean.id, cc.attrs.guid)}"
    onbegin="$.efc.busy($.messages.sending);"
    oncomplete="$.efc.busy('', true);"
    value="Send offer to this dealer">
</a4j:commandButton>

【问题讨论】:

标签: jsf-2 richfaces


【解决方案1】:

根据文档:

“MethodExpression 表示一个动作侦听器方法,当用户激活此组件时将通知该方法。该表达式必须评估为采用 ActionEvent 参数的公共方法,返回类型为 void。”

javax.el.MethodExpression (签名必须匹配 void actionListener(javax.faces.event.ActionEvent))

【讨论】:

  • 那么可以使用&lt;a4j:commandLink&gt; 完成我想要的吗?我尝试使用动作而不是动作侦听器,但也无法使其正常工作。我最终只是切换到了&lt;div&gt;,其样式类似于like,并称为&lt;a4j:jsfunction&gt; onClick。
  • 不优雅的解决方案是同时拥有链接和按钮。带有样式 display:none 的按钮将被隐藏。 a4j:commandLink 与 onClick javascript 将触发按钮上的 onclick 事件并触发往返。
  • a4j:commandLink 的 Action 属性必须评估不带参数并返回 Object 的公共方法。它用于导航目的。
猜你喜欢
  • 1970-01-01
  • 2013-05-25
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多