當我單擊按鈕時,警告消息不會顯示。如果我點擊一個按鈕,它應該顯示警報消息作爲延遲3分鐘的成功。當我單擊按鈕中的h:命令按鈕時,警告消息不會顯示
當我點擊按鈕時,首先它沒有響應第二次,只有它從bean獲取值。 爲什麼第一次不加載的原因是什麼?
XHTML代碼:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
<script>
var myVar;
function myFunction() {
myVar = setTimeout(function(){message();},3000);
}
function message(){
myVar=setTimeout(function() {
if(#{mytest.count}===0) {
alert("Fails");
}
else {
alert("Success");
}
},3000);
}
</script>
</h:head>
<h:body>
<h:form>
<h:commandButton onclick="message();" action="#{mytest.func}" value="click"/>
</h:form>
</h:body>
</html>
Managed Bean的代碼:
package com.display;
import javax.faces.bean.ManagedBean;
@ManagedBean
public class Mytest {
private int count=0;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void func(){
this.count=1;
System.out.println("function called");
System.out.println("count value is -->"+count);
}
}
從你在哪裏調用'myFunction的()'函數? –