Declaring Beans in a faces-config.xml file

Declaring Beans in a faces-config.xml file

<?xml version=’1.0′ encoding=’UTF-8′?>
<faces-config version=”2.2″
    xmlns=”http://xmlns.jcp.org/xml/ns/javaee&#8221;
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
    xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd”&gt;

    <managed-bean>
    <managed-bean-name>Customer</managed-bean-name>
        <managed-bean-class>com.linaittech.Customer</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
    
    
    
  <managed-bean>
    <managed-bean-name>Mirek</managed-bean-name>
        <managed-bean-class>com.linaittech.Mirek</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
    
</faces-config>

We have two beans in our JSF application (from Customer and Mirek classes). Beans are just Java objects used in Java web technologies. In these classes, you should write the decorator:

@ManagedBean

It’s associated with the  <managed-bean> </managed-bean> tags. You see that. 

<managed-bean-name>Mirek</managed-bean-name>

These tags are associated with the name of our class.

<managed-bean-class>com.linaittech.Mirek</managed-bean-class>

These tags are associated with the path to our class (package name + class name)

<managed-bean-scope>request</managed-bean-scope>

These tags are associated with setting the bean scope in our application. Request scope’s life has a short span. Scopes are:

none – no life span

application – application life span, so always

session – duration of session life span

request – client’s request life span

If you create another bean, you should write another section of cod that will manage your class. Thanks to that, you will have no problem with running the view part of your application that are xhtml files.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s