How can I have previous value of checkbox in Spring?

How can I have previous value of checkbox in Spring?

Is it possible to have the previous value of checkbox along with new value?

My problem is, I have to execute some code, only if the value of checkbox is true, also if it was already true, then I am not suppose to perform the same action again. Currently what I am doing is , for every checkbox I am having previous value holder too. If the value is changed only then I perform the action ( and it is true ), and set value of previous value holder to the new value.

programmatically create a spring context


Spring Injecting into Struts RequestProcessor
You can add a change listener to the checkbox.

Spring Open JPA
When the checkbox changes the state, you can directly call your special code..
What is the simplest solution to integrate 2 apps within a Tomcat server?
Or when you have a preference page, in which the checkbox is inside, you have to store the state of the preference page and check, if you have changed states inside..
netbeans and Apache Derby Embedded + spring

Does Spring-MVC annotation based bean validation support for collection-based property ? (Spring-MVC)

Spring 2 Hibernate Annotation


Two approaches of task distribution in a multi tier application
Are you using the spring mvc JSP tablib or velocity/freemarker macros?. If you are, they should be ouputting a hidden field with the existing value of the checkbox in the HTML with an underscore "_" in front of it.

Spring does this to help determine whether the checkbox was unchecked or just not submitted.. You should be able to appropriate this hidden field for your purposes, i.e.

you can check for the value of the hidden field and compare it to the actual checkbox field value.. See Spring MVC 2.5 Checkbox tag.


To do this properly you will need to do the comparison without relying on the client side to record the old value as this could allow tampering.. On submit, Spring MVC rebuilds the old version of the command before updating it with the new values submitted from the client.

You will need to save the old value somewhere before the bind phase begins.

. To do this, in the formBackingObject method (which gets called again after a POST submit), put a copy of the value in the request object.

Then in the onSubmit method, you can retrieve the value from the request for the comparison.

You could also record it in a different field on the command.. I find this SimpleFormController cheat sheet very helpful for figuring out the execution order of the methods.

It should help you out here too..

82 out of 100 based on 72 user ratings 1222 reviews