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