我想在JSF支持bean中獲取JavaScript值。我已經試過如下:在JSF支持bean中獲取由JavaScript設置的隱藏值
JSF:
<h:inputHidden id="fileName" value="#{TestBean.fileName}" />
<a4j:commandButton id="button" value="Send Mail" action="#{TestBean.send}" onclick="onCall()"/>
豆:
public String send() {
System.out.println("File Name: " + fileName);
}
JS:
function onCall(){
//value changes dynamically everytime this function is called
document.getElementById('case:fileName').value = '123';
}
問題與此代碼是:首次是從第二次獲取支持bean 中的空字符串,它在t中獲得先前生成的值他有java腳本功能。
我哪裏錯了,我該如何解決?
此替代方案適合您嗎? 'value =「#{fileName}」'設置值的bean屬性使用'setPropertyActionListener'或者將param作爲參數添加到你的方法'#{send(fileName)}? – djmj 2012-08-09 13:10:12