1

How to display a custom message or remove input for integer field in jsp form when user enters white-space in input-field in spring mvc, validated using hibernate validator? It currently shows:

Failed to convert property value of type java.lang.String to required type int for property freePasses; nested exception is java.lang.NumberFormatException: For input string: ""

7
  • Use bootsrap or jquery validator in front end Commented Jul 18, 2018 at 9:13
  • 1
    Yes , that is an alternative but what if I want to show custom message using java in controller side? Commented Jul 18, 2018 at 9:15
  • Use @NotNull annotation. Commented Jul 18, 2018 at 9:18
  • 1
    @NotNull working for String fields , displaying custom message as required,but for int fields still showing same :Failed to convert property value of type java.lang.String to required type int for property freePasses; nested exception is java.lang.NumberFormatException: For input string: "" Commented Jul 18, 2018 at 9:30
  • 1
    Use wrapper class to declare integer varieble. Refer stackoverflow.com/questions/12211734/… Commented Jul 18, 2018 at 9:42

1 Answer 1

1

Use wrapper class to declare integer variables so that wrapper class will convert whitespace to null.

or

refer below link for common solution

Hibernate validation annotation - validate that at least one field is not null

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.