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 first 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?