PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/example/src/main/java/example/shared/FieldVerifier.java

https://code.google.com/p/gwtrpccommlayer/
Java | 45 lines | 12 code | 2 blank | 31 comment | 2 complexity | 247d31d6aa9b4e2d288ee23ea305fd0c MD5 | raw file
  1. package example.shared;
  2. /**
  3. * <p>
  4. * FieldVerifier validates that the name the user enters is valid.
  5. * </p>
  6. * <p>
  7. * This class is in the <code>shared</code> packing because we use it in both
  8. * the client code and on the server. On the client, we verify that the name is
  9. * valid before sending an RPC request so the user doesn't have to wait for a
  10. * network round trip to get feedback. On the server, we verify that the name is
  11. * correct to ensure that the input is correct regardless of where the RPC
  12. * originates.
  13. * </p>
  14. * <p>
  15. * When creating a class that is used on both the client and the server, be sure
  16. * that all code is translatable and does not use native JavaScript. Code that
  17. * is note translatable (such as code that interacts with a database or the file
  18. * system) cannot be compiled into client side JavaScript. Code that uses native
  19. * JavaScript (such as Widgets) cannot be run on the server.
  20. * </p>
  21. */
  22. public class FieldVerifier
  23. {
  24. /**
  25. * Verifies that the specified name is valid for our service.
  26. *
  27. * In this example, we only require that the name is at least four
  28. * characters. In your application, you can use more complex checks to ensure
  29. * that usernames, passwords, email addresses, URLs, and other fields have the
  30. * proper syntax.
  31. *
  32. * @param name the name to validate
  33. * @return true if valid, false if invalid
  34. */
  35. public static boolean isValidName(String name)
  36. {
  37. if (name == null)
  38. {
  39. return false;
  40. }
  41. return name.length() > 3;
  42. }
  43. }