O'Reilly logo

Struts Kick Start by Kevin Bedell, James Turner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Perils of Automatic Type Conversion

One of JSP’s features is that it will automatically convert text fields from forms into a number of common data types (including floats and ints) during form submission. However, you shouldn’t use this feature with Struts.

The reason is that if you use this feature, any nonnumeric value placed in this field will cause it to stick a zero in the field.

You could check to make sure that the values were nonzero in your validator (assuming that zero isn’t a valid value). But, even then, when you returned to the form with the error, the field would have put in zero as the last value submitted, rather than what the user typed.

For example, if you had a field called height that was defined in your ActionForm ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required