Can some please validate this?
My application uses Struts Action Form.
I am also using Value Objects.
I am not doing validations using validations.xml and validator-rules.xml. I'm
performing simple validations on server side as follows:
Can some one please check the below code and tell me if what I am doing is correct?
In Action Form "validate" method, the code as follows:
===== code in validate method of ActionForm ==========
ActionErrors errs = new ActionErrors();
MyValues val = new MyValues();
try {
val.setInputField(inputField_);
} catch (IllegalArgumentException ex) {
errs.add(FLD_INPUT_FIELD,new
ActionError("myviewform.error_input_field",ex.getMessage()));
}
===== code in Value Object - MyValues =============
public void setInputField(String val) {
if (val==null || val.length()==0)
throw new IllegalArgumentException("Illegal null parameter passed to
setInputField");
if (val!=null && val.length()>100) // max length of this field is 100
throw new IllegalArgumentException("Illegal parameter value too long
passed to setInputField,value="+val);
inputField_=val;
}// end of setInputField
============================================================
With the above code, can I say that the validations are written in "validate" method
of ActionForm? Someone mentioned that since I'm performing actual validations in
MyValues, the validations are not being done in ActionForm, and so it does not follow
Struts Framework rules. Is this true? Please clarify.