Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

passing content of inputText to bean  RSS feed

Matthew Cserhati
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18720
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!