hi,

I provided declarative XML validation for a form where the action would expose primitive type properties. The problem is that a primitive type property left blank in the form would never be caught as not provided by the "required" validation. The property would instead be set with the default value for such primitive type. When the text field in the form is left empty the "required" validation wont work but instead setExchangeRate would be called with 0.0 value, same for int, boolean etc. The workaround is to using the corresponding boxed type e.g. Double, Integer but e.g. Boolean would not work like this.

TIA
regards,
Giovanni

************ MyForm.jsp ****************

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>

<s:form id="formSimulation" action="%{targetAction}" method="post" theme="%{currentTheme}"> <s:textfield tooltip="Provide the Exchange Rate" label="Exchange Rate" cssStyle="width: 250px;" name="exchangeRate" /> <!-- etc -->
   <s:submit value="%{buttonLabel}" align="center"/>
</s:form>

************ MyAction.java **************

public class MyAction {
 // ...
 public void
 setExchangeRate(double anExchangeRate) {
    theExchangeRate = anExchangeRate;
 };
}

********** MyAction-validation.xml ********

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd";>
<!--  START VALIDATOR: SimulationRun -->
<validators>
<field name="exchangeRate">
   <field-validator type="required">
      <message>Exchange rate must be provided</message>
   </field-validator>
   <field-validator type="double">
      <message>Exchange rates must be of numeric type</message>
   </field-validator>
</field>
</validators>
<!--  END VALIDATOR: SimulationRun  -->




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to