Java Reference
In-Depth Information
The generated managed bean source simply consists of the annotated managed bean
class containing a single public no argument constructor.
package com.ensode.jsf.managedbeans;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
public class RegistrationBean {
/** Creates a new instance of RegistrationBean */
public RegistrationBean() {
The @ManagedBean annotation marks the class as a JSF managed bean. By default,
the managed bean name defaults to the class name ( RegistrationBean , in our case)
with its first character switched to lower case ( registrationBean , in our case). If we
want to override the default name, we can do it by specifying a different name in the
NetBeans New JSF Managed Bean wizard, or by simply setting the name attribute
of @ManagedBean to the desired value. In general, sticking to the defaults allows for
more readable and maintainable code therefore we shouldn't deviate from them
unless we have a good reason.
With the addition of any Java class annotated with @ManagedBean in our project,
we no longer need to register FacesServlet in web.xml as the JSF runtime in the
application server will automatically register the servlet.
The @RequestScoped annotation designates that our managed bean will have a
scope of request. Had we selected a different scope when creating the managed
bean with the NetBeans wizard, it would have been annotated with the appropriate
annotation corresponding to the selected scope. Session scoped managed beans
are annotated with the @SessionScoped annotation. Application scoped managed
beans are annotated with the @ApplicationScoped annotation. Managed beans with
a scope of "none", are annotated with the @NoneScoped annotation. View scoped
managed beans are annotated with the @ViewScoped annotation.
At this point, we need to modify our managed bean by adding properties that will
hold the user-entered values.
Search WWH ::

Custom Search