Skip to content

Commit

Permalink
constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
Gavin King committed Nov 16, 2009
1 parent 8ef027e commit 9746ed4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions reference/en-US/example.xml
Expand Up @@ -5,17 +5,20 @@

<para>
Let's illustrate these ideas with a full example. We're going to implement user login/logout for an application
that uses JSF. First, we'll define a request-scoped bean to hold the username and password entered during login:
that uses JSF. First, we'll define a request-scoped bean to hold the username and password entered during login,
with constraints defined using annotations from the Bean Validation specification:
</para>

<programlisting role="JAVA"><![CDATA[@Named @RequestScoped
public class Credentials {
private String username;
private String password;
@NotNull @Length(min=3, max=25)
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
@NotNull @Length(min=6, max=20)
public String getPassword() { return password; }
public void setPassword(String password) { this.password = password; }
}]]></programlisting>
Expand All @@ -36,19 +39,17 @@ public class Credentials {
</h:form>]]></programlisting>

<para>
Users are represented by a JPA entity, with constraints defined using annotations defined by the Bean Validation
specification:
Users are represented by a JPA entity:
</para>

<programlisting role="JAVA"><![CDATA[@Entity
public class User {
private @NotNull @Length(max=25) @Id String username;
private @NotNull @Length(min=3, max=25) @Id String username;
private @NotNull @Length(min=6, max=20) String password;
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String setPassword(String password) { this.password = password; }
}]]></programlisting>

<para>
Expand Down

0 comments on commit 9746ed4

Please sign in to comment.