【问题标题】:action method is not called in <a4j:commandLink> tag<a4j:commandLink> 标签中未调用 action 方法
【发布时间】:2012-08-23 14:03:12
【问题描述】:
<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>

问题是deleteUser方法没有在backing bean中被调用为什么会这样。但是它正在调用javascript函数请帮助我。

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    问题是您在“onclick”方法中返回了一个值。假设你的calljs方法返回true或者false,代码必须改成:

    <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 代码将如下所示(或类似的):

    <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 提交。通过我提供的更新代码,代码将类似于:

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


    更新:建议的代码将适用于 RichFaces 3.x。如果你使用 RichFaces 4.x 你的 commandLink 应该是这样的

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

    【讨论】:

    • 感谢门多萨的回复。现在该方法在支持 bean 中被调用,但 reRender="viewUserGrid" 部分没有被刷新。我的js调用method()
    • @satish 你用的是什么 RichFaces 版本?
    • 富人面孔 3x iam 正在使用。感谢您展示如何接受答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多