| Author |
Instantiating SelectItems from Spring bean
|
Lance Cash
Greenhorn
Joined: Oct 19, 2009
Posts: 17
|
|
|
We have a selectOneMenu that we are using over and over in our app with the same selectItems in it, EVERY time. I know there is a way to instantiate this via a Spring bean, but I do not know the way. Could someone possibly teach me the ways of the Jedi masters? Thanks. Lance.
|
 |
Davie Lin
Ranch Hand
Joined: Aug 05, 2007
Posts: 294
|
|
Hi Lance
Are you saying that your current selectOneMenu is instantiated manually?
is it via
in your jsp or facelets?
so you want to know how to do this in a Spring bean? do you currently have this spring bean implemented and is this bean interface with a hibernate layer? Does the Spring bean that you mention currently is being called from your JSF backing bean? You will probably have to provide more detailed info if you want to get any helpful answer from someone here
|
 |
Lance Cash
Greenhorn
Joined: Oct 19, 2009
Posts: 17
|
|
Ok, sorry for the sparse details. I was kinda looking for some generalities to start. Anywho, this is what our current jsf pages are littered with:
I know there is a way to define this so that these things are instantiated by Spring once at startup and used throughout the app. Any direction would be greatly appreciated...even if it is just to point me in the right direction. Thanks. Lance.
|
 |
Davie Lin
Ranch Hand
Joined: Aug 05, 2007
Posts: 294
|
|
Ok, assume that those itemValues and itemLabels are stored in the database and you have a spring bean to access that database. Your JSF backing bean has a reference to the spring bean
Here would be a direction to try in your JSF backing bean, have a method that return a List
for your ice face, you would use
remember, you use selectItems, not selectItem like you had before
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14568
|
|
I do this a lot. Commonly I have a Spring bean that's loading the menu list from a persistent source. I also link Spring and JSF using the connector in faces-config. That allows me to inject that persistence-layer Spring Bean (DAO) into a JSF backing bean. The backing bean wraps the database data with the JSF model objects (SelectItem) and makes it available as a property value for the selectOneMenuItems list.
To use one instance for all users, I put the backing bean into "application" scope. The reason for having a backing bean instead of making the Spring bean directly emit the models is simply to preserve the consistent tier organization of the webapp and keep the JSF stuff out of the persistence stuff.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: Instantiating SelectItems from Spring bean
|
|
|