在< a4j:commandLink>中未调用action方法.标签 [英] action method is not called in <a4j:commandLink> tag

查看:92
本文介绍了在< a4j:commandLink>中未调用action方法.标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<a4j:commandLink onclick="return call();" action="#{bean.deleteUser(all_user.userID)}" reRender="viewUserGrid">
<h:graphicImage style="border-style:none;" url="/images/delete.jpg"  height="10px" />
</a4j:commandLink>

问题是后备bean中没有调用deleteUser方法,为什么会这样.但是它正在调用javascript函数,请帮帮我.

The problem is deleteUser method is not getting invoked in the backing bean why is it so.But it is invoking the javascript function Please help me.

推荐答案

问题是您要在"onclick"方法中返回一个值.假设您的call js方法返回true或false,则必须将代码更改为:

The problem is that you're returning a value in your "onclick" method. Assumming that your call js method returns a true or false, the code must be changed to:

<a4j:commandLink onclick="if (!call()) return false;"
    action="#{bean.deleteUser(all_user.userID)}"
    reRender="viewUserGrid" limitToList="true">
    <h:graphicImage style="border-style:none;" url="/images/delete.jpg"  height="10px" />
</a4j:commandLink>

进一步的解释:

为您的实际代码生成的HTML代码如下所示(或类似的内容):

The HTML generated code for your actual code will look like this (or something familiar):

<a href="#" id="formName:j_id45351"
    name="formName:j_id22"
    onclick="return call(); A4J.AJAX.Submit('formName',event, '');">
<!-- the rest of the HTML generated code... -->

如果看到的话,return call();方法位于onclick的开头,因此不会调用ajax提交.根据我提供的更新代码,代码将类似于以下内容:

If you see, the return call(); method is at the beginning of the onclick, so the ajax submit won't be called. By the code updated I provide, the code will be similar to this:

<a href="#" id="formName:j_id45351"
    name="formName:j_id22"
    onclick="if (!call()) return false; A4J.AJAX.Submit('formName',event, '');">
<!-- the rest of the HTML generated code... -->

进行此更改后,如果您的call js方法返回false,则不会提交ajax调用,如果返回true,则将进行您的ajax调用.请注意,如果javascript方法不返回任何值,则默认情况下将返回false.

With this change, if your call js method returns false, then the ajax call won't be submitted, if it returns true, then your ajax call will be made. As a note, if a javascript method doesn't return any value, it will return false by default.

更新:建议的代码将与RichFaces 3.x一起使用.如果您使用RichFaces 4.x,您的commandLink应该看起来像

UPDATE: The proposed code will work with RichFaces 3.x. In case you use RichFaces 4.x Your commandLink should look like

<a4j:commandLink onclick="if (!call()) return false;"
    action="#{bean.deleteUser(all_user.userID)}"
    render="viewUserGrid">
    <h:graphicImage style="border-style:none;" url="/images/delete.jpg"
        height="10px" />
</a4j:commandLink>

这篇关于在&lt; a4j:commandLink&gt;中未调用action方法.标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆