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]