action method is not called in <a4j:commandLink> tag

故事扮演 提交于 2019-12-11 04:22:08

问题


<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>

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.


回答1:


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>

Further explanation:

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... -->

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... -->

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.


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>


来源:https://stackoverflow.com/questions/12093461/action-method-is-not-called-in-a4jcommandlink-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!