Announcement Announcement Module
No announcement yet.
Using Custom Tags with Spring Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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!


  • #2
    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.


    • #3
      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.



      • #4
        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.


        • #5
          Thanks a lot.

          Thanks a lot Marten I will try that!

          Kind regards.


          • #6
            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.



            • #7
              Just to complete this:

              public class MyTag extends TagSupport {
                      private WebApplicationContext _applicationContext;
              	public MyTag() {
              		_applicationContext = RequestContextUtils.getWebApplicationContext(
              	public int doStartTag() throws JspException {
                            Object bean = _applicationContext.getBean("someName");
                            // ...


              • #8
                Thanks a lot!

                Already working... :O)