【发布时间】:2011-04-11 02:28:56
【问题描述】:
我想在 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 中获取空字符串 从第二次开始,它会在 java 脚本函数中获取先前生成的值。
我哪里出错了,我该如何解决?
【问题讨论】:
-
这种替代方案适合您吗?
value="#{fileName}"设置值的 bean 属性使用setPropertyActionListener或将参数作为参数添加到您的方法 `#{send(fileName)}?
标签: javascript jsf ajax4jsf