How do I configure the default values of Java beans?

See Also  

Your applications will use many Java beans:

To use the EnterpriseItem, EnterpriseItems, or Identity managed beans, or any other beans in the development of your application, the beans must be declared in the application configuration resource file (faces-config.xml). These declarations ensure that the JavaServer Faces implementation can automatically create new instances of the beans whenever they are needed. The bean's resources and default property settings should also be defined in this file.

Note:    The faces-config.xml file is also used to configure navigation rules which define the navigation flow of your web application. For more information, see How do I define the navigation flow of my application?.

For example, here is a template for a managed bean declaration:

<managed-bean>

    <description>Description of the managed bean.</description>

    <managed-bean-name>Name of the managed bean.</managed-bean-name>

    <managed-bean-class>Fully qualified class name.</managed-bean-class>

    <managed-bean-scope>Scope of the bean.</managed-bean-scope>

    <managed-bean-property>

        <property-name>Name of the bean property.</property-name>

        <value>Default value of the property.</value>

    </managed-bean-property>

</managed-bean>

The basic details of the managed bean are specified by the <description>, <managed-bean-name>, and <managed-bean-class> tags. The <managed-bean-name> tag contains the name that is used to reference the bean within JSF component attributes. For example, consider the opening ItemsGrid tag.

<boe:itemsGrid id="myItemsGrid" enterpriseItems="#{enterpriseItems}">

To have the ItemsGrid component reference an EnterpriseItems bean in this way, using the enterpriseItems attribute, a managed bean declaration must exist in faces-config.xml:

<managed-bean-name>enterpriseItems</managed-bean-name>

The <managed-bean-class> tag should contain the fully qualified name of the bean class, for example:

<managed-bean-class>

com.businessobjects.jsf.appcontrols.model.EnterpriseItems

</managed-bean-class>

The <managed-bean-scope> tag defines where the bean is stored and when it is available. For the EnterpriseItem, EnterpriseItems, or Identity beans, use session scope:

<managed-bean-scope>session</managed-bean-scope>

Finally, use zero or more <managed-bean-property> tags to define the default values of bean properties, which are specified by the <property-name> and <value> subtags. Many properties will take in a basic type, such as a string or integer. However, if the bean property is not a basic type, then you need to also specify the fully qualified name of the property class used as the type. For example:

<managed-bean-property>

    <property-name>nextRangeButton</property-name>

    <property-value>com.businessobjects.jsf.sdk.properties.SubmitButtonProps</property-class>

    <value>#{myButtonProps}</property-value>

</managed-bean-property>

The #{myButtonProps} statement refers to a SubmitButtonProps bean. For more information on property beans, see How do I use property classes?

The JavaServer Faces implementation processes faces-config.xml at application startup time. When a bean is first referenced from the page, the JavaServer Faces implementation initializes it and stores it in the defined scope if no instance of the bean exists. The bean is then available for all pages in the application.



Business Objects
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/