Results 1 to 8 of 8

Thread: Using Custom Tags with Spring

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Posts
    11

    Default Using Custom Tags with Spring

    Hi there,

    I am a newbie to Spring, so please excuse me if I am asking you a silly question! :wink:

    We are developing our new web-plattform with Spring. We are using some of our own custom tags which need access to our database. So I should be able to inject a Dao-Bean into this custom tag, shouldn't I?!

    How do I accomplish that??? It does NOT work, if I register the custom tag in the applicationContext.xml. (Probably, because Spring is using its own instance of the tag class)

    For filters I have figured out, that I have to use the FilterToBeanProxy class from acegi to integrate the filter with Spring. Is there a similar solution for custom tags?

    Thanks in advance!

    Chris

  2. #2
    Join Date
    Jul 2005
    Posts
    2

    Default

    Hi all,

    I have a similiar scenario and no solution yet.
    The web framework is used as struts + spring + hibernate.

    We built a tag library which access the database via spring w/ hibernate.
    Some codes are written in the ApplicationContext.xml to inject the data manager to the tag library.

    The tag library did get the manager at constructor. I checked it with debugger. However, the manager is null when the tag lib is called by JSP.

    But I found the manager of struts action is injected by container in every call to the action. I guess the problem is the manager not set at every call to tag library.

    Anyone can kindly suggest a solution.

    Thanks in advance.
    Eddie

  3. #3

    Unhappy Same problem

    I'm in the same scenario. I use a custom tag that is supossed to be injected a Spring managed dao manager to access the database in search of a few records.
    I don't get this dao manager injected. It's value is always null and therefore I get a nullpointerException everytime the custom tag tries to render.
    Any ideas?
    Did any of you solve your problem?

    Thanks in advance.

    Fran.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    A TAG cannot and will not be under the control of spring, it is constructed by the servlet container. You will have to pull the dependencies in.

    Use the RequestContextUtils for that, you can get a reference to the application context and pull the beans from there.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5

    Default Thanks a lot.

    Thanks a lot Marten I will try that!

    Kind regards.

  6. #6

    Unhappy Access to the request.

    Hi Marten,

    If I try to use RequestContextUtils.getApplicationContext method, a "request" is needed as a parameter.

    Could you explain a little how to get access to the applicationContext?

    I supose once I get the applicationContext I need the use the getBean("myDao") method.

    Thanks in advance.

    Fran

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 5
    Last Post: Aug 9th, 2008, 05:30 AM
  3. Replies: 1
    Last Post: May 26th, 2005, 04:14 PM
  4. Replies: 1
    Last Post: May 14th, 2005, 05:41 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •