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.
Initializing data and lifecycle hooks
From the course: Java EE: JavaServer Faces JSF
Initializing data and lifecycle hooks
- [Instructor] One of the most pervasive mistakes I've seen in the wild concerning JSF is how to initialize data in a managed bean. It may be local data within the managed bean, or a data source like a database or a rest service. One of my most popular answers in StackOverflow explains this bug in detail. Search JSF managed bean initialization to find it. Let's say we need to display a list of dog breeds in a JSF page. Our hypothetical Facelets page will pull this data from the ViewScoped bean we created earlier. Let's add a List, dogs. Say it's a List of names. Or Strings, rather. Let's fix that. Import. And then, we encapsulate. We want the setter and the getter. There. We've defined our List variable of dogs, encapsulated it, and now we need to fill it with data. It's sometimes tempting to do this in the getter of a list, like so. We have, dogs variable assigned to a new ArrayList. And then, we can add String, like say, corgi, and one more, a retriever. Or even in the constructor…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.