Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to pass value from jsf to bean class?  RSS feed

koti satheesh
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Could anyone suggest / help me out getting JS -> JSF value to Bean class? I have tried with below code:
JSF code:
<h:commandButton styleClass="buttonpos" value="Get Value" action="#{myBean.action}" onclick="document.getElementById('crForm:hiddenInput').value">
<h:inputHidden id="hiddenInput" value="#{myBean.action}"/>
Java Beans
public class CurrencyExchangeBean {
protected static Logger logger = ILogger.getLogger(CurrencyExchangeBean.class);
private String hiddenInput;
public void action() {
System.out.println(" action() hiddenInput: " + hiddenInput);" action()hiddenInput :"+hiddenInput);
public void setHiddenInput(String hiddenInput) {
this.hiddenInput = hiddenInput;
public String getHiddenInput(){" getHiddenInput() - hiddenInput :"+hiddenInput);
return hiddenInput;
Tim Holloway
Posts: 18661
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: If you use the "Code" button to wrap your java and XML samples with formatting tags, they'll be easier to read.

Your "onclick" javascript snippet does nothing. All it is is a reference to a control value.

I think what you probably wanted was more like this:

This would assign a new value to the HTML form control that backs the form and it would inform the submit process to proceed. Without the "return true", it's probably aborting the submit, since if you really didn't want the submit to happen, you'd return false. I say "probably", because I get onclick and onsubmit confused, and I'm too lazy to read the manual.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!