Ver Mensaje Individual
  #5 (permalink)  
Antiguo 16/04/2015, 00:36
Avatar de Profesor_Falken
Profesor_Falken
 
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 9 meses
Puntos: 182
Respuesta: Struts2 validacion double generica

Buenas,

Efectivamente el field-validator double no verifica si lo introducido es o no un numero y hay que completarlo con una regex, por ejemplo, como has hecho.

Esto puede resultar un poco confuso, y de hecho hay mucha gente con tu misma duda:
http://www.coderanch.com/t/433036/St...idation-Number

Para verificarlo, basta mirar el codigo fuente del validador:
http://grepcode.com/file/repo1.maven...Validator.java

Cita:
public void More ...validate(Object object) throws ValidationException {
76 String fieldName = getFieldName();
77 Double value;
78 try {
79 Object obj = this.getFieldValue(fieldName, object);
80 if (obj == null) {
81 return;
82 }
83 value = Double.valueOf(obj.toString());
84 } catch (NumberFormatException e) {
85 return;
86 }

87
88 parseParameterValues();
89 if ((maxInclusiveValue != null && value.compareTo(maxInclusiveValue) > 0) ||
90 (minInclusiveValue != null && value.compareTo(minInclusiveValue) < 0) ||
91 (maxExclusiveValue != null && value.compareTo(maxExclusiveValue) >= 0) ||
92 (minExclusiveValue != null && value.compareTo(minExclusiveValue) <= 0)) {
93 addFieldError(fieldName, object);
94 }
95 }

Como puedes ver en negrita, si no puede convertir a double, ignora el problema y hace un return.



Un saludo
__________________
If to err is human, then programmers are the most human of us