• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiating SelectItems from Spring bean

 
Lance Cash
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 294
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic