Prototype Scope in Spring

I use a simple web application that uses struts2 (view)- tiles (view) – Spring – Hibernate.
It is working fine. I have a strange behavior explained below.

1. Consider I have form. I fill up the text boxes, select boxes and press Submit. The values are getting displayed. Perfect!
2. If I go to any other page and coming to the previous page again. The old values given are still retained by default and results are displayed as per the earlier selection.
3. This condition became worse when I have a try to insert records being fetched in the form. The records are getting duplicated with incremented IDs in database.

The reason is I dint specify the beans in prototype scope!!

Thanks for coderanch.com forum!

http://www.coderanch.com/t/485636/Struts/Application-Frameworks/Request-Value-getting-retained

Advertisements

One thought on “Prototype Scope in Spring

  1. Spring MVC Controller beans are generally designed to be thread safe singletons without any state and therefore can be singletons.

    Struts Actions are generally designed to maintain state and therefore must not be singletons. Actions can be prototypes or request scoped bean. I’ve never used them as session scoped beans, but I’m guessing that they could be, if you wanted to maintain the information for the entire session.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s