SMTP
Server
IMAP
Mail Store
methods to handle the following
four tasks:
■ ■■ ■ Perform processing associated
with navigation from one Web
page to another
■ ■■ ■ Handle action events
■ ■■ ■ Perform validation on a component’s value
■ ■■ ■ Handle value-change events
Accordingly, in a backing bean
called emailJSFManagedBean, we
create the getter and setter meth-
ods necessary for each of the Web
components listed earlier (except
the Send E-mail button). If the
recipient’s e-mail address is a vari-
able of type String called to, Listing 1
shows how the getter and setter meth-
ods would be defined.
@ManagedBean, as shown in Listing 1,
is a declaration that registers the
backing bean as a resource with the
JSF implementation. In addition,
@RequestScoped is the annotation
that identifies the managed bean as a
resource that exists only in the scope of
the request. In other words, the bean
exists for the duration of a single HTTP
request for the user’s interaction with
the Web application.
We also create two specific methods
within the backing bean.
The first method’s function is to validate all e-mails submitted by the user
on the Web application (see Listing 2).
package useJavaMail;
JavaMail
SMTP
SP
IMAP
SP
JavaMail API
JAF
@ManagedBean
@RequestScoped
public class emailJSFManagedBean {
private String to;
/** Creates a new instance of emailJSFManagedBean */
public emailJSFManagedBean() {
to = null;
}
JAVA IN ACTION
Figure 4
application. Accordingly, the following
workflow is proposed:
■ ■ Step 1: Create a backing bean.
■ ■ Step 2: Create Web pages using component tags.
■ ■ Step 3: Map the FacesServlet instance.
/**
* @return the to
*/
public String get To() {
/**
* @param is the "to" to set
*/
public void set To(String to) {
}
ABOUT US
Creating a Backing Bean
A backing bean is a type of managed
bean specific to the JSF technology. It
holds the logic of the Web application
and interacts with
the Web compo-
nents contained
in the Web pages.
The backing bean
can contain pri-
vate attributes that
correspond to each
Web component,
getter and setter
methods referring to
the attributes, and
Download all listings in this issue as text
The JavaMail API
is a package that
provides general
e-mail facilities,
such as reading,
composing, and
sending electronic
messages.
blog
message = "E-mail is required";
Note that the validation e-mail
method takes three arguments:
■ ■ The context of the JSF implementation, in order to pass error messages
from the managed bean to the
user interface
■ ■ The identifier UIComponenttoValidate
of the Web component that is invoking the method, which, in this case, is
a text input field (see Listing 1) method
that takes user input as an argument—
user input is illustrated in Figure 1
■ ■■ ■ The variable value, which contains
the e-mail address that needs to
be validated
Accordingly, the code shown in
Listing 2 accomplishes the following
tasks: