問題是,您在「onclick」方法中返回一個值。 Assumming您call
JS方法返回一個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
的開始,所以阿賈克斯提交將不會被調用。通過更新我公司提供的代碼,該代碼將類似於此:
<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調用方法()<腳本類型= 「文/ JavaScript的」> \t \t \t函數調用(){ \t \t \t \t變種R =確認( 「你要刪除的用戶」); \t \t \t \t如果(R == TRUE){ \t \t \t \t \t switchStatus(); \t \t \t \t \t return true; \t \t \t \t}其他{ \t \t \t \t返回FALSE; \t \t \t \t} \t \t \t} \t \t – satish
@satish你使用的是什麼RichFaces的版本? –
豐富的面孔3x iam using.Thanks如何接受答案 – satish