• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Avoid Default Values for Double or Any Wrapper Class

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,

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.

Thanks in Advance

Cheers,
Prasath
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

ApplicationResources.properties
zerosuppress=###.##

JSP
<bean:write name="myForm" property="myDouble" formatKey="zerosupress" />


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.
 
Prasath Thirumoorthy
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Merrill Higginson,

Im using <html:text/> tag only.

Here the piece of code how Im using in my application:

In my ActionForm
*****************************************************
Class MyForm {

private TransferObject objTransferObject = new TransferObject();

}
*****************************************************

Class TransferObject {

private Double amout;

}
*****************************************************

In my Jsp

<html:text name="MyForm" property="objTransferObject.amount"/>

*****************************************************

While Im running the application Im getting 0.0 in the text box as default value.I want to avoid this.

Since the TransferObject carries the values and using hibernate the values are inserted in the database.

Since the TransferObject's amount property has Double as data type which is not String type we are referring this property in the Jsp.Whether it will create problem while validation as u told.

Is it a wrong approach that placing the TransferObject inside the formbean ?

Thanks in Advance

Cheers,
Prasath
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

- Brent
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic