Java EE 7 Application Developer — Question 26
You are building the User Preferences page of an application. A user can change values, such as his or her name, password, address, company, and so on.
These values are sent to a CDI backing bean via AJAX when the user tabs out of each field. However, the values must be retained in the CDI bean and stored in the database only when the user clicks the Save button.
Which two scopes will allow your CDI bean to retain its state while the user is interacting with the User Preferences page? (Choose two.)
Answer options
- A. Dependent
- B. View
- C. Session
- D. Request
- E. Application
Correct answer: C, D
Explanation
The correct answers are C (Session) and D (Request) because the Session scope allows the CDI bean to retain its state across multiple interactions during the user's session, while the Request scope retains the state for the duration of a single request. The Dependent scope does not maintain state, the View scope is not suitable for retaining user interactions, and the Application scope is too broad for this context.