Back Forum Reply New

Can Spring Taglibs do this?

Hi,

Im New to Spring so sorry for the question without researching it myself.

Currently in our web environment, we've set up the WebAppContext and the listener in our web.xml. Spring starts up, and works fine. We can pull our injected beans out of the context with:

WebApplicationContextUtils.getRequiredWebApplicati  onContext(this.getServletContext());
SessionFactory sf = (SessionFactory) ctx.getBean(quot;sessionFactoryquot;);

My question is this: Does Spring have a tag that allows us to do something like lt;spring:getBean var=quot;mySessionFactoryquot; value=quot;x.y.z.sessionFactoryquot; gt;  - That way I don't have to look up the context each time.

Thanks in advance!
Jonathan

sorry... I don't quite understand why you need to pull spring beans in a web application - maybe I just didn't understand the question or the problem.

Why don't you use Spring's IOC (or better know as Dependency Injection) where you create a beans and inject them to another bean (or classes actually)? e.g. create a DAO-class where you inject other beans (sessionFactory bean).

I've been a member of a big Spring WEB project and we didn't pull a single bean from the Spring applicationContext... magic of the IOC

Secondly why or where do you need the sessionFactory in your JSP-page?

The Session Factory was just an example (apparently a poor one). In reality what you mentioned is exactly what we are doing. All are DAO's have the session factory being injected into them, etc. . .

The reason we are pulling beans into a web app is because we are using an older system and integrating Spring into it. Essentially we are trying to get away from an older technology, but we have to take baby steps. So there is no MVC infrastructure (such as Spring's), and to obtain the data we need we will have to get the beans within our page to play with them.

In your big spring web app, how do you interact with your data and business logic without retrieving your bean object's from the context?

And to go back to my original question: The reason I ask if spring has that functionality is so on each request we are not doing that long line of context lookup, or perhaps a little bit better placing the context in the app scope, and looking it up through there. I was hoping spring would hide that from us and we could just use some taglib.

Normally there is some MVC in place and then you inject everything you need in your controller, that constructs a model and the model is displayed by your view technology of choice. So need to work with beans directly in your jsp.

But afaik there is no support for what you want by default. But you could always write your own (small) tag library which contains a tag which does that what you want.
¥
Back Forum Reply New