Monday, January 7, 2013

Re: How to validate TextBox fields?


Yes I know this side. But it still does not tell me:
- how to validate the name before creating the person object (which I'm looking for in terms of numbers like int age; There I'd first like the validator to catch if it's a valid age before creating the person object)

Your validation annotations are defined on the person so you have to create a person, fill its annotated properties with values and then validate that person. How should the validation framework know what to validate if you dont provide a person instance?
 

- how to display an annotation error message beneath a textbox

Create a error message label that you can show/hide/update based on the ConstraintViolation you get from validating your class. If Person.name has a validation violation then constraintViolation.getPropertyPath() should be "name". 

In the validation example, all messages are appended into a single message and then displayed using a label (method: sendPersonToServer()):
https://gwt.googlesource.com/gwt/+/releases/2.5/samples/validation/src/main/java/com/google/gwt/sample/validation/client/ValidationView.java

If your app is big enough it is maybe worth it to also look into GWT's editor framework which will save you from writing a lot of "glue" code between your UI and your model classes you want to edit.

-- J.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/dJmLLSQFeuUJ.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment