Management of BACKING BEAN in JSF

xiaoxiao2021-03-06  93

BACKING Bean Management

Another critical function of Web applications is proper management of resources. This includes separating the definition of UI component objects from objects that perform application-specific processing and hold data. It also includes storing and managing these object instances in the proper scope. Web application Another key function is to manage resources. This includes separating the definition of the UI component object and processing the function specified by the application and the object saved by the application. It also includes saving and managing these object instances in an appropriate range.

A typical JavaServer Faces application includes one or more backing beans, which are JavaBeans components (see JavaBeans Components) associated with UI components used in a page. A backing bean defines UI component properties, each of which is bound to either a component's value or a component instance. a backing bean can also define methods that perform functions associated with a component, including validation, event handling, and navigation processing. JSF a typical application includes one or more background the bean, the page, which is a UI component and JavaBeans components about the relationship. A background bean defines the properties of the UI component, each with the value or instance of the component. A background bean can also define and component-related, and perform certain features, including authentication, event processing, navigation processing.

To bind UI component values ​​and instances to backing bean properties or to reference backing bean methods from UI component tags, page authors use the JavaServer Faces expression language (EL) syntax. This syntax uses the delimiters # {}. A JavaServer Faces expression can be a value-binding expression (for binding UI components or their values ​​to external data sources) or a method-binding expression (for referencing backing bean methods). It can also accept mixed literals and the evaluation syntax and operators of the JSP 2.0 expression language (See Expression Language). If you want to bind the value of the UI component and the instance to the background bean's attribute or through the Mark of the UI component references the background bean method, the page developer needs to use the JSF expression language syntax. This syntax uses the "# {}" indicator. A JSF expression can be a value bound (binding UI component or their value to external data source) or method binding (reference to the backend bean method). It can also use syntax in JSP2.0. To illustrate a value-binding expression and a method-binding expression, let's suppose that the userNo tag of the guessNumber application referenced a method that performed the validation of user input rather than using the LongRangeValidator: To demonstrate the method of tying and binding expression value Depending to the expression, let us assume that the userno tag of the GuessNumber application references a method to verify, not using longrangevalidator.

Value = "# {usernumberbean.usernumber}"

Validator = "# {usernumberbean.validate}" />

This tag binds the userNo component's value to the UserNumberBean.userNumber backing bean property. It also refers to the UserNumberBean.validate method, which performs validation of the component's local value, which is whatever the user enters into the field corresponding to this tag. This Tags the value of the UserNo component to the userNumberBean.userNumber Background Bean, which verifies the local value of the component.

The property bound to the component's value must be of a type supported by the component. For example, the userNumber property returns an Integer, which is one of the types that a UIInput component supports, as shown in Developing the Beans. Property is bound to The value of the component must be the data type supported by the component. For example, the UserNumber property returns an Integer, which is a UIINPUT supported data type. In addition to the validator attribute, tags representing a UIInput can also use a valueChangeListener attribute to refer to a method that responds to ValueChangeEvents, which a UIInput component can fire. In addition to the validator attribute, UIInput tag may be used to refer to a property valueChangeListener The method corresponds to the ValueChangeeevents.

A tag representing a component that implements ActionSource can refer to backing bean methods using actionListener and action attributes. The actionListener attribute refers to a method that handles an action event. The action attribute refers to a method that performs some processing associated with navigation and returns a Logical Outcome, Which The Navigation System Uses to DETERMINE Which Page To Display Next. A component that is expressed by tag, if ActionSource is implemented, you can use the ActionListener and Action properties to reference the background Bean method. Action attributes reference a method to process an action event. The method referenced by the Action property makes some processing, performs page navigation, and returns a logical result, and the navigation system uses this logic result to determine which page needs to be displayed.

A Tag Can Also Bind A Component Instance TO A Backing Bean Property. It does this by Referencing The Property from The Binding Attribute: A tag can bind the instance of the component to the properties of the background bean. You can be implemented by reference a property from a binding attribute.

The property referenced from the binding attribute must accept and return the same component type as the component instance to which it's bound Here is an example property that can be bound to the component represented by the preceding example inputText tag:. Attribute cited by binding properties There must be the same data type as the component instance type. UIINPUT Usernocomponent = NULL;

...

Public void setusernocomponent (UIINPUT UsernOComponent) {

THIS.USERNOComponent = Usernocomponent;

}

Public uiinput getusernocomponent () {

Return Usernocomponent;

}

When a component instance is bound to a backing bean property, the property holds the component's local value. Conversely, when a component's value is bound to a backing bean property, the property holds its model value, which is updated with the local value during the Update Model Values ​​Phase of the Life Cycle. When a component instance is bound to the properties of the background bean, this property saves the local value of the component. Conversely, if the value of a component is bound to the properties of the background bean, The property saves the pattern value. Update the operation of the local value occurs during the process of update mode values ​​in the life cycle.

Binding a Component Instance To a Bean Property Has these Advantages: Binding an instance of a component to the properties of the bean have some of the advantages.

The Backing Bean CoNent Attributes. The background bean can process the properties of the component.

The BACKING Bean Can Instantiate Components Rather Than Let The Page Author Do So can exempt components instead of making page developers to work.

Binding a Component's Value To a Bean Property Has these Advantages: Bind the component's value to the property of the bean has some advantages:

The Page Author Has More Control Over The Component Attributes. The page developer has more control over the properties of the component.

The Backing Bean Has No Dependencies on The JavaServer Faces API (Such as The Ui Component Classes), Allowing for Greater Separation of the Presentation Layer from The Model Layer. Background Bean does not have to rely on the JSF API, which can be better able to behave and The pattern layer is separated.

The JavaServer Faces Implementation CAN Perform Conversions On The Data Based on The Type of The Bean Property WITHETETETER. The JSF can make data type conversion without having to have developers to make a converter. In most situations, you will bind a component's value rather than its instance to a bean property. You'll need to use a component binding only when you need to change one of the component's attributes dynamically. For example, if an application renders a component Only Under Certain Conditions, IT CAN Set The Component's Rendered Property To Which The Component is Bound. In most cases, the value of the binding component should be used instead of the instance of the component to the properties of the bean. Only when you need to dynamically change the properties of the component, you need to bind the instance to the bean properties. For example, if you need to display a component in a specific case, you only need to access the binding attribute in the background bean.

Backing beans are created and stored with the application using the managed bean creation facility, which is configured in the application configuration resource file, as shown in Adding Managed Bean Declarations. When the application starts up, it processes this file, making the beans available to The Application and Instantiating Them When The Component Tags Reference The. The creation and saving of the background bean is done by the creation of the manageable bean, configuring in the application's configuration file. When an application is started, it processes this file, when the component's tag references them, allowing these beans to be available and instantiate them.

转载请注明原文地址:https://www.9cbs.com/read-121703.html

New Post(0)