In my Struts Application, In the Transfer Object Im using the Wrapper Class say Integer,Double .. for the attributes.Im getting the default values 0 for Integer and 0.0 for Double in my textfield.How can i avoid these default values and i need to show just the empty text field.
If you're displaying static text on the page, just use the formatKey attribute of the <bean:write> tag. This specifies the name of an entry in your ApplicationResources.properties file that contains a mask for how you want to display the value. Here's an example:
If this is being displayed in an <html:text> box, It is strongly recommend that you not use data types other than string for text input. This is mainly because it makes validation messy.
What you would need to do in this case is create a separate getter (e.g. getFormattedAmount) on your ActionForm that displays the double value as a String formatted the way you want. You also need to create a setter (e.g. setFormattedAmount) that accepts a String as input and converts it to a Double.
I would suggest creating ActionForm classes that contain String properties. That is what my project does. It is a little bit of a pain having to write the code required to translate between your data object and your form fields. Another issue with using wrapper classes is that if the user enters "12345A" in the text box and submits the page, it will redisplay with a validation message saying "the value you entered in the salary field is invalid" but the field will display as empty.
This translation code is a good place to do formatting. For example, you can format decimal values to a limited number of decimals, format date string or build up a user name from first, middle and last fields.
subject: How to Avoid Default Values for Double or Any Wrapper Class