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.
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
Joined: Oct 19, 2009
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.
Joined: Aug 05, 2007
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
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.
An IDE is no substitute for an Intelligent Developer.