views:

63

answers:

2

I'm using Spring MVC and have a page in my web application where I have a mailing address field that is mandatory and a radio button with a question asking 'Is the billing address the same as the mailing address?' Neither yes or no is selected by default to force the user to select an answer to the question via validation.

I have currently implemented it so that in the controller, if the radio button value is 'Yes', I copy the value of the mailing address into the billing address.

My validation works like so: If the radio button has been set to yes then don't validate the billing address input fields, otherwise perform validation on those fields.

Is this an ok way to implement this functionality? The only other thing I could think of is to get JQuery to populate the values when the radio button is selected.

Why would you do the copying in the Java controller code versus Javascript?

A: 

I havent worked with Spring, but validation issues are aapplication wide, dispite of the framework. I've seen something in my development years, that you must know, is that validation should be performed on the server side and on the client side.

Always remember that Javascript validations can be bypassed using Firebug, or some other Mozilla plugin, but server validation is harder/almost impossible to bypass. Keep this in mind before you make the desition of leaving validation only for Javascript.

Hope I can help!

David Conde
A: 

I agree with dconde, the only thing I would suggest is disabling the Billing Address fields in the UI if the user selects "Billing Address Same". This will provide concrete visible feedback that there is no need to enter values

Aaron Saunders