Get hidden value set by JavaScript in JSF backing bean
I want to get a JavaScript value in a JSF backing bean. I've tried the following:
JSF:
<h:inputHidden id="fileName" value="#{TestBean.fileName}" />
<a4j:commandButton id="button" value="Send Mail" action="#{TestBean.send}" onclick="onCall()"/>
Bean:
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';
}
Problem with this code is: for the fir开发者_开发知识库st time it is fetching empty string in backing bean from the second time onwards it is getting previously generated value in the java script function.
Where did I go wrong and how can I solve it?
I just tried this code and it works fine on my machine. As I can see the code is not exactly copy-pasted, because there is mistake in send()
method. It declares return type String
, but it doesn't return anything.
Maybe your mistake is somewhere in the part of code you didn't copy here.
You will need to use a4j's commandButton
with a actionParam
inside. Refer to this answer: https://stackoverflow.com/a/10534779/268016
精彩评论