File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes passing content of inputText to bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "passing content of inputText to bean" Watch "passing content of inputText to bean" New topic

passing content of inputText to bean

Matthew Cserhati

Joined: Apr 04, 2014
Posts: 9
Hello everyone,

I have an xhtml file with this content:

<h:inputText tabindex="7" styleClass="input" id="title" value="#{register.title}"

Basically I want the user to enter his title (e.g. Mr., Dr.), which would be passed on to a bean which would send this information to me in email.

I also have a bean called register, along with setters and getters:

private String title;
public String getTitle() {
return title;
public void setTitle(String title) {
this.title = title;

I want to pass this information to a String called body, within the bean:

body = body+"Title: "+this.title+"\n";

I would then send the String in an email.
Any suggestions?

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17417

JSF is a Model/View/Controller (MVC) framework where you write the View templates (xhtml) and the Models (backing beans) and the Controllers are supplied by JSF itself.

If you submit a form with valid data in it, JSF will automatically invoke the appropriate "set" methods for the properties you referenced in the backing bean. You don't have to write any Java code.

Conversely, whatever value you set in a backing bean will be reflected in the View (web page) the next time the View is (re)displayed. Again, done automatically, as JSF's Controllers invoke the propery "get" methods.

Within the action method (actions are not part of MVC, they're the business interface to the Model) the action code can likewise obtain the value posted to the backing bean from the form by invoking the property "get" method. Or by direct field access, if you prefer, but I like to use the get/set methods, since they're easier to trace and the compiler optimizes them anyway.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: passing content of inputText to bean
It's not a secret anymore!