This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
koti satheesh
Greenhorn
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}"/>
</h:commandButton>
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);
logger.info(" action()hiddenInput :"+hiddenInput);
}
public void setHiddenInput(String hiddenInput) {
this.hiddenInput = hiddenInput;
}
public String getHiddenInput(){
logger.info(" getHiddenInput() - hiddenInput :"+hiddenInput);
return hiddenInput;
}}
faces-config.xml
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>eman.ism.sc.ui.request.CurrencyExchangeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
 
Tim Holloway
Bartender
Posts: 18531
61
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!