think you nilesh, i anderstand the problem and i have the solution
so , now, i wnat to validate in client by a regular expression and in the server by an other regular expression ,
because in client i have a string like
"22222,33333,22222"
i must validate with this reg exp:
^[0-9]+(( *|,) *[0-9]+)*$
in hte server part i have a property editor whitch parse a String and make a Set .
i must validate evry Instance on this set.
i try this code:
--validation.xml--
Code:
field property="instances" depends="required,maskList">
<msg name="maskList" key="errors.maskListmsg"/>
<arg0 key="smsform.instances" />
<var>
<var-name>maskList</var-name>
<var-value>^[0-9]+$</var-value>
</var>
<var>
<var-name>mask</var-name>
<var-value^[0-9]+(( *|,) *[0-9]+)*$</var-value>
</var>
<var>
<var-name>champ</var-name>
<var-value>destination</var-value>
</var>
</field>
--validator-rules.xml--
Code:
<validator name="maskList"
classname="com.validation.ListFieldChecks"
method="validateMaskList"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.springframework.validation.Errors"
depends=""
msg="errors.invalid">
<javascript><![CDATA[
function validateMaskList(form) {
//alert('1');
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
oMasked = new maskList();
//alert('2');
for (x in oMasked) {
//alert('3');
var field = form[oMasked[x][0]];
if ((field.type == 'text' ||
field.type == 'textarea') &&
(field.value.length > 0)) {
//alert('4');
if (!matchPatternList(field.value, oMasked[x][2]("mask"))) {
if (i == 0) {
focusField = field;
}
fields[i++] = oMasked[x][1];
isValid = false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return isValid;
}
function matchPatternList(value, mask) {
//alert('5 '+value);
//alert(mask);
return mask.exec(value);
}
]]>
</javascript>
</validator>
--com.validation.ListFieldChecks.java--
Code:
public static boolean validateMaskList(Object bean, ValidatorAction va, Field field, Errors errors){
String champ = field.getVarValue("champ");
Object liste=null;
try {
liste = PropertyUtils.getProperty(bean,field.getProperty());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Collection set= (Collection)liste;
Field f1=new Field();
f1.setProperty(champ);
f1.addArg(field.getArg(0));
Var maskList = field.getVar("maskList");
maskList.setName("mask");
f1.addVar(maskList);
Msg msg= new Msg();
msg.setName("maskList");
msg.setKey(field.getKey());
f1.addMsg(msg);
for (Iterator iter = set.iterator(); iter.hasNext();) {
Object element = (Object) iter.next();
if(!FieldChecks.validateMask( element, va, f1, errors)){
return false;
}
}
return true;
}
now i have a propblem whit initializing the Field.