Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-613

Prototype scoped Spring beans

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Fixed
    • 1.3.0-beta1
    • 1.3.4, 1.4-M3
    • wicket-spring
    • None
    • JDK 6, Jetty

    Description

      I copied the following text from my discussion on wicket-user, and was asked to open an issue, so here it is:
      http://www.nabble.com/Prototype-scoped-Spring-beans-tf3849285.html

      For a more complex form I wanted to use a "stateful" Springbean, to which I applied scope="prototype". The idea is to have one bean instance for every Form instance. I would access the bean with PropertyModels and direct method calls during construction (i.e. setting initial state from input parameters) and during events, which would alter the state. I inject the bean into the Form with @SpringBean annotation.

      This works somehow, but sometimes, especially after using the backbutton, I had the problem that the internal state was reset. So I analyzed the stack in the constructor of the bean implementation, and found out that it was called twice during construction of the Form. First, during the super() call, and then again in the next line during a method call on that bean. I appended both stacktraces below. The proxy itself does not change.

      This happens again after going back and e.g. submitting again. This results in a NPE, because the internal state is reset.

      I understand from reading the mailing list that the Wicket-Proxy does nothing but a lookup in the Application context, and does not know or care about spring scope.

      And here I'm a little stuck. I am already considering to put the state into the Form, and make the Bean a singleton without any internal state. As that would mean some heavy refactoring, I would prefer a way where the Spring acces would work as I want. Or is this a wrong way altogether?

      Attachments

        Activity

          People

            ivaynberg Igor Vaynberg
            mindhaq RĂ¼diger Schulz
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: