he hecho algunas búsquedas en la web y en stackoverflow para ver cómo manejar el siguiente mensaje que me subo a uno de mis pantallas:uso Primavera de mensajes typeMismatch
No se pudo convertir el valor de propiedad de Tipo [java.lang.String] al tipo requerido [java.lang.Long] para la propiedad 'qtyToShip'; la excepción jerarquizada es java.lang.IllegalArgumentException: No se pudo analizar el número: unparseable número: "a"
De la investigación y de mirar la web me supone que añadir lo siguiente a mi archivo errors.properties haría producir los resultados deseados:
typeMismatch.shippingCommand.qtyToShip=1. Invalid value for Qty To Ship, accepts only numbers.
typeMismatch.qtyToShip=2. Invalid value for Qty To Ship, accepts only numbers.
shippingCommand.qtyToShip=3. Invalid value for Qty To Ship, accepts only numbers.
qtyToShip=4. Invalid value for Qty To Ship, accepts only numbers.
typeMismatch.java.lang.NumberFormatException=5. Invalid value for {0}, accepts only numbers.
typeMismatch.java.lang.Integer=Must specify an integer value.
typeMismatch.java.lang.Long=Must specify an integer value.
typeMismatch.java.lang.Float=Must specify a decimal value.
typeMismatch.java.lang.Double=Must specify a decimal value.
typeMismatch.int=Invalid number entered
typeMismatch=Invalid type entered
I añadir valores enteros para el mensaje para determinar cuál sería aparecer.
Ahora en la parte superior de mi JSP Tengo el siguiente:
<center>
<spring:hasBindErrors name="shippingCommand">
<c:if test="${errors.errorCount > 0 }">
<h4>Following errors need to be corrected:</h4>
<font color="red">
<c:forEach items="${errors.allErrors}" var="error">
<spring:message code="${error.code}" arguments="${err.arguments}" text="${error.defaultMessage}"/><br />
</c:forEach>
</font>
</c:if>
</spring:hasBindErrors>
</center>
Lo anterior es fuera de mi forma, dentro de mi Formulario I tienen las siguientes (probando ideales)
Así que el resultado es que cuando ejecuto mi código para desencadenar el error, veo que dentro de mi formulario recibo el siguiente mensaje:
1. Invalid value for Qty To Ship, accepts only numbers.
que viene de esto: typeMismatch.shippingCommand.qtyToShip
el exterior de la forma displayes:
Invalid type entered
Lo que no entiendo es por qué soy capaz de mostrar el mensaje correcto dentro de mi forma, pero ¿no afuera?
En el controlador de E han añadido los siguientes:
@Override
protected void initBinder(HttpServletRequest pRequest, ServletRequestDataBinder pBinder) throws Exception
{
NumberFormat numberFormat = NumberFormat.getInstance();
pBinder.registerCustomEditor(Long.class, "qtyToShip", new CustomNumberEditor(Long.class, numberFormat, false));
}
Gracias
Son Of A Gun - eso hizo el truco. Gracias – boyd4715