I did several searches on the Internet and on stackoverflow to see how to process the following message that I receive on one of my screens:
Failed to convert property value, enter [java.lang.String] into the required type [java.lang.Long] for the property 'QtyToShip'; nested exception java.lang.IllegalArgumentException: Failed to parse number: Unparseable number: "a"
From research and browsing the Internet, I assumed that adding the following to the errors.properties file would produce the desired results:
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 am adding integer values ββto the message to determine which one will be displayed.
Now at the top of my JSP I have the following:
<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>
The above is outside my form, inside my form I have the following (testing ideals)
So, the results are that when I run my code to run the error, I see that inside my form I get the following message:
1. Invalid value for Qty To Ship, accepts only numbers.
What comes from this: typeMismatch.shippingCommand.qtyToShip
Appearance of the form:
Invalid type entered
I donβt understand why I can display the correct message inside my form, but not outside?
In the controller, I added the following:
@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)); }
thanks