• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to pass value from jsf to bean class?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic