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

Can a SpringBean's state be serialized?

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Not A Problem
    • 1.5.7
    • None
    • wicket-spring
    • None
    • Windows/Linux, JDK 6, Spring 3.1.0

    Description

      I have Wicket page containing a SpringBean-injected object that contains state. This state is not serialized and hence not available when the user revisits the page via the Back button.

      In the example below, the DAODataProvider object has an entityClass property. When the user goes back to the page via the Back button, the dataProvider and dataProvider.dao properties are available, but dataProvider.entityClass is null.

      public class DemoPage extends WebPage {
      	@Inject @SpringBean DAODataProvider dataProvider;
      	
      	public DemoPage(final PageParameters parameters) throws ClassNotFoundException, IntrospectionException {
          	super(parameters);
      		
      		dataProvider.setEntityClass(UserAccount.class);
      		add(new CRUDPanel("panel", UserAccount.class, dataProvider));
          }
      
      }
      
      
      @Component
      @Scope("request")
      public class DAODataProvider extends SortableDataProvider {
      	@Inject protected GeneralDAO dao;
      	
      	private Class<?> entityClass;
      	
      	public DAODataProvider() {
      		super();
      	}
      }
      

      The solution seems to be to do this:

      public class DemoPage extends WebPage {
      @Inject @SpringBean DAODataProvider dataProvider;

      public DemoPage(final PageParameters parameters) throws ClassNotFoundException, IntrospectionException

      { super(parameters); dataProvider.setEntityClass(UserAccount.class); add(new CRUDPanel("panel", UserAccount.class, dataProvider)); }

      @Override
      protected void onBeforeRender()

      { dataProvider.setEntityClass(UserAccount.class); super.onBeforeRender(); }

      }

      Is there a good way to indicate that a SpringBean-injected object should have its non-injected properties serialized, to avoid doing the onBeforeRender workaround above?

      Attachments

        Activity

          People

            Unassigned Unassigned
            shoe54 Shu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: