User Preferences Page Scopes | SEO Best Practices

CDI Bean Scopes | User Preferences Page

Question

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.)

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D. E.

CD.

The two scopes that will allow a CDI bean to retain its state while the user is interacting with the User Preferences page and until the Save button is clicked are the View and Session scopes.

The View scope is a contextual scope that lasts for the duration of a single HTTP request-response cycle, during which a user interacts with a specific view of the application. The view can be a JSP, JSF page, or any other presentation technology. The View scope is designed to hold state for the view so that it can be reused on subsequent requests. The View scope is a good fit for this use case since it retains state only during the duration of the user's interaction with the User Preferences page, which is typically a single view.

The Session scope is a contextual scope that lasts for the duration of a user's session with the application. The Session scope is designed to hold state for the user across multiple requests and views of the application. The Session scope is a good fit for this use case since it allows the CDI bean to retain state across multiple views, which may be useful if the user needs to navigate away from the User Preferences page and come back later to complete the form.

On the other hand, Dependent, Request, and Application scopes are not suitable for this use case because:

  • The Dependent scope lasts as long as the bean that it injects into exists. Therefore, it is not suitable for retaining state between requests or views.

  • The Request scope lasts only for the duration of a single HTTP request. Therefore, it is not suitable for retaining state between requests or views.

  • The Application scope lasts for the entire lifecycle of the application. Therefore, it is not suitable for retaining state for a specific user or request.