so, I should have all form-properties to be of String type and convert to
Double and then validate is it?
if that is the case then, why do we have the below data types? what is it's
purpose?
http://struts.apache.org/struts-action/userGuide/building_controller.html
The types supported by DynaActionForm include:
java.math.BigDecimal
java.math.BigInteger
boolean and java.lang.Boolean
byte and java.lang.Byte
char and java.lang.Character
java.lang.Class
double and java.lang.Double
float and java.lang.Float
int and java.lang.Integer
long and java.lang.Long
short and java.lang.Short
java.lang.String
java.sql.Date
java.sql.Time
java.sql.Timestamp
Thanks.
From: Laurie Harper <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <user@struts.apache.org>
To: user@struts.apache.org
Subject: Re: formbean of double type value chages when submitting the form
Date: Thu, 23 Mar 2006 23:55:00 -0500
fea jabi wrote:
In struts config
<form-bean name="Form1"
type="org.apache.struts.validator.DynaValidatorForm" dynamic="true">
<form-property name="netRevenue" type="java.lang.Double"/>
..............................
...............................
.......................
</form-bean>
In prepare action I am not doing anything with the data.
IN JSP
<html:text name="Form1" property="netRevenue" />
validation.xml
<field property="netRevenue" depends="required,double">
<msg name="required" key="lbl.required"/>
<msg name="double" key="lbl.notvalid"/>
</field>
Dispatch action :
public ActionForward save(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
DynaValidatorForm frm = (DynaValidatorForm)form;
ActionMessages messages = (ActionMessages)frm.validate( mapping,
request );
if ( messages != null && !messages.isEmpty() ) {
saveErrors(request, messages);
setUp(request, frm);
return (mapping.findForward("validationFailed"));
}else {
if(isTokenValid(request, true)) {
//save
}
}
return mapping.findForward("successSave");
}
When the page get displayed the value in the textfield for netRevenue is
Blank i.e the textfield in empty.
When I debug and see netRevenue value is null.
But when the click a submit button the value is changed to 0.0. The
textfield has 0.0 value in it.
When I debug, when it comes to the very first statement of save method
before validating itself in Dispatch action i.e
DynaValidatorForm frm = (DynaValidatorForm)form;
itself the value of the netRevenue is 0.0 instead of null.
Not sure why it's null before and 0.0 when I validate.
can someone explain me why it's so? and how to make the values be same
before and after clicking on submit button save.
This is normal behaviour, and is a result of the way Struts populates the
form bean from the request parameters. Struts uses BeanUtils under the
covers to handle conversion from request parameter string values to your
form bean property types. The standard way to handle a value that can't be
converted to a Double is to return a place-holder default, 0.0.
You have two options: 1) you can configure BeanUtils to return a different
default (or null); this will avoid the 0.0 value, but you still wont get
the user-submitted data back if it's a string value that can't be converted
to Double; 2) you can change your form bean property type to String instead
of Double.
Option 2 is almost certainly what you want, since that's the only possible
way of redisplaying all possible invalid inputs.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee®
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]