From the course: Java EE: JavaServer Faces JSF

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Long-lived managed beans

Long-lived managed beans

From the course: Java EE: JavaServer Faces JSF

Start my 1-month free trial

Long-lived managed beans

- [Instructor] We start with the application scope bean. The longest-lived, broadest-managed scope. A class annotated with this will be instantiated when it's first referenced in any part of the application. And it is then kept alive for the entirety of the up-time of the application. Let's try one out. We go to our Projects, right click, we want a new Java class. Let's call this our SampleApplicationScopedBean inside our com.samples.linkedin.jsf.bean package. Click on Finish. And we have a plain old Java class. Let's now add the @Named annotation, provide the imports, supply a name. We'll call it the sampleAppScopedBean. Next, we apply the @ApplicationScoped annotation on line 16. Let's do our imports with Control+Shift+i. Remember to be very sure that you're importing from the javax.enterprise.context package. Click OK, and there, we have our ApplicationScoped bean. Bear in mind, only one instance of this backing bean will exist inside the entire application. So we can sort of think…

Contents