I am having a screen in which all values being dislayed are stored in java backing bean. i have to code particular functionality under which whenever a person cliks OK button at end of screen a call needs to be made to server to compare current values on screen with stored value in backing beans. If values are different an alert is sent to user informing him that values have changed. If he opts yes then new values are retained and old values lost. The new values will also be stored in same bean. Can any one using some sample code explain me how this can be done .....
In summary how can i use my form bean's same field to store different values on each form submission and also retain old values for comparision purpose....
There's no silver bullet that I am aware of for doing this. You'll just need to store old values in session (most likely) and then compare the new values coming in off the request to the session values. Replacing values in both scopes when necessary.
You can write a custom validator that will read the new values off the request, and compare them against the values in the backing bean.
Remember, your new values will not overwrite the old values until after validation.
Something like this for a String value (if you are using non-String values you will need to convert your request value to the correct type:
Now you want to do a confirm and then proper submit, to do this you can set a backing bean boolean to true on the first submit and check for it in the validator - if they that value is true you know this is the second submit (the confirm) and you can ignore the validation.