Author: dan.j.allen
Date: 2009-11-13 14:30:41 -0500 (Fri, 13 Nov 2009)
New Revision: 5054
Modified:
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/pom.xml
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/java/HelloWorld.java
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/pom.xml
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/java/HelloWorld.java
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
Log:
add bean validation in the example class and view
Modified:
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/pom.xml
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/pom.xml 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/pom.xml 2009-11-13
19:30:41 UTC (rev 5054)
@@ -44,11 +44,13 @@
<artifactId>jsf-api</artifactId>
</dependency>
- <!-- Optional, but pretty useful. -->
- <!-- <dependency>-->
- <!-- <groupId>javax.servlet</groupId>-->
- <!-- <artifactId>jstl</artifactId>-->
- <!-- </dependency>-->
+ <!-- Optional, but pretty useful. -->
+ <!--
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+ -->
<!-- Optional, but highly recommended. -->
<dependency>
@@ -74,7 +76,20 @@
<scope>runtime</scope>
</dependency>
+ <!-- Bean Validation API (JSR 303) -->
<dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ </dependency>
+
+ <!-- Bean Validation Implementation -->
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>4.0.0.GA</version>
+ </dependency>
+
+ <dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>el-impl</artifactId>
<scope>runtime</scope>
@@ -123,10 +138,10 @@
</connectors>
<!-- force friendly name instead of artifact name + version -->
<contextPath>${build.finalName}</contextPath>
- <!-- Where the BeanManager is constructed. This is where you'll
declare datasources. -->
+ <!-- Where the BeanManager is constructed. This is where you'll
declare datasources. -->
<jettyEnvXml>\${basedir}/src/test/resources/jetty-env.xml</jettyEnvXml>
- <!-- This parameter will auto-deploy modified classes. -->
- <!-- You can save changes in a file or class and refresh your browser
to view the changes. -->
+ <!-- This parameter will auto-deploy modified classes. -->
+ <!-- You can save changes in a file or class and refresh your browser
to view the changes. -->
<scanIntervalSeconds>3</scanIntervalSeconds>
</configuration>
</plugin>
Modified:
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/java/HelloWorld.java
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/java/HelloWorld.java 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/java/HelloWorld.java 2009-11-13
19:30:41 UTC (rev 5054)
@@ -1,24 +1,70 @@
package ${package};
-import java.io.Serializable;
+import javax.enterprise.inject.Model;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-@RequestScoped
-@Named
-public class HelloWorld implements Serializable
+import org.hibernate.validator.constraints.Email;
+import org.hibernate.validator.constraints.NotEmpty;
+
+public @Model class HelloWorld
{
+ private final String text = "Hello World!";
+
+ private String letters;
+
+ private String numbers;
+
+ private String email;
+
public HelloWorld()
{
System.out.println(this.getClass().getSimpleName() + " was
constructed");
}
- private final String text = "Hello World!";
-
public String getText()
{
return text;
}
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
+ @NotNull
+ @NotEmpty
+ @Pattern(regexp = "[A-Za-z]*", message = "must contain only
letters")
+ public String getLetters()
+ {
+ return letters;
+ }
+
+ public void setLetters(String letters)
+ {
+ this.letters = letters;
+ }
+
+ @NotNull
+ @NotEmpty
+ @Digits(fraction = 0, integer = 2)
+ public String getNumbers()
+ {
+ return numbers;
+ }
+
+ public void setNumbers(String numbers)
+ {
+ this.numbers = numbers;
+ }
+
+ @NotNull
+ @NotEmpty
+ @Email
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public void setEmail(String email)
+ {
+ this.email = email;
+ }
+
+}
Modified:
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-11-13
19:30:41 UTC (rev 5054)
@@ -1,13 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html">
-<h:head>
- <title>JSF Demo</title>
-</h:head>
-<h:body>
- <h1>Does Weld Work?</h1>
- <p>My weld-injected bean says <span style="color:
blue;">#{helloWorld.text}</span> in a JSF EL dialect.</p>
- <p>You can write the same value using the Unified EL: <span style="color:
green;">${helloWorld.text}</span></p>
-</h:body>
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html">
+ <h:head>
+ <title>Weld Starter Application</title>
+ </h:head>
+ <h:body>
+ <h1>Hello World!</h1>
+ <p>My weld-injected bean says <span style="color:
blue;">#{helloWorld.text}</span> in a JSF EL dialect.</p>
+ <p>You can write the same value using the Unified EL: <span
style="color: green;">${helloWorld.text}</span></p>
+
+ <h:form>
+ <h2>Bean Validation examples</h2>
+ <p>Enforces the annotation-based constraints defined on the model
class.</p>
+ <table>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="letters"
value="Letters:"/>
+ </th>
+ <td>
+ <h:inputText id="letters"
value="#{helloWorld.letters}"/>
+ <h:message for="letters" style="color:
red;"/>
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="numbers" value="Numbers (max two
digits):"/>
+ </th>
+ <td>
+ <h:inputText id="numbers"
value="#{helloWorld.numbers}"/>
+ <h:message for="numbers" style="color:
red;"/>
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="email" value="Email:"/>
+ </th>
+ <td>
+ <h:inputText id="email"
value="#{helloWorld.email}"/>
+ <h:message for="email" style="color: red;"/>
+ </td>
+ </tr>
+ </table>
+ <p>
+ <h:commandButton action="check" value="Check"/>
+ <h:outputText value=" All clear!"
rendered="#{facesContext.postback and empty facesContext.messageList}"
style="color: green;"/>
+ </p>
+ </h:form>
+ </h:body>
</html>
Modified:
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/pom.xml
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/pom.xml 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/pom.xml 2009-11-13
19:30:41 UTC (rev 5054)
@@ -48,11 +48,13 @@
<scope>provided</scope>
</dependency>
- <!-- Optional, but pretty useful. -->
- <!-- <dependency>-->
- <!-- <groupId>javax.servlet</groupId>-->
- <!-- <artifactId>jstl</artifactId>-->
- <!-- </dependency>-->
+ <!-- Optional, but pretty useful. -->
+ <!--
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>jstl</artifactId>
+ </dependency>
+ -->
<!-- Optional, but highly recommended. -->
<dependency>
@@ -74,23 +76,6 @@
</exclusions>
</dependency>
- <!-- Sun Bean Validation API (JSR 303) -->
- <!--<dependency>-->
- <!-- <groupId>javax.validation</groupId>-->
- <!-- <artifactId>validation-api</artifactId>-->
- <!--</dependency>-->
- <!-- Bean Validation Implementation -->
- <!--<dependency>-->
- <!-- <groupId>org.hibernate</groupId>-->
- <!-- <artifactId>hibernate-validator</artifactId>-->
- <!-- <version>4.0.0.GA</version>-->
- <!--</dependency>-->
- <!-- Additional Bean Validation Validation Dependency-->
- <!--<dependency>-->
- <!-- <groupId>org.slf4j</groupId>-->
- <!-- <artifactId>slf4j-log4j12</artifactId>-->
- <!-- <version>1.4.2</version>-->
- <!--</dependency>-->
</dependencies>
<build>
<finalName>${artifactId}</finalName>
Modified:
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/java/HelloWorld.java
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/java/HelloWorld.java 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/java/HelloWorld.java 2009-11-13
19:30:41 UTC (rev 5054)
@@ -1,24 +1,70 @@
package ${package};
-import java.io.Serializable;
+import javax.enterprise.inject.Model;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-@RequestScoped
-@Named
-public class HelloWorld implements Serializable
+import org.hibernate.validator.constraints.Email;
+import org.hibernate.validator.constraints.NotEmpty;
+
+public @Model class HelloWorld
{
+ private final String text = "Hello World!";
+
+ private String letters;
+
+ private String numbers;
+
+ private String email;
+
public HelloWorld()
{
System.out.println(this.getClass().getSimpleName() + " was
constructed");
}
- private final String text = "Hello World!";
-
public String getText()
{
return text;
}
- private static final long serialVersionUID = 1L;
-}
\ No newline at end of file
+ @NotNull
+ @NotEmpty
+ @Pattern(regexp = "[A-Za-z]*", message = "must contain only
letters")
+ public String getLetters()
+ {
+ return letters;
+ }
+
+ public void setLetters(String letters)
+ {
+ this.letters = letters;
+ }
+
+ @NotNull
+ @NotEmpty
+ @Digits(fraction = 0, integer = 2)
+ public String getNumbers()
+ {
+ return numbers;
+ }
+
+ public void setNumbers(String numbers)
+ {
+ this.numbers = numbers;
+ }
+
+ @NotNull
+ @NotEmpty
+ @Email
+ public String getEmail()
+ {
+ return email;
+ }
+
+ public void setEmail(String email)
+ {
+ this.email = email;
+ }
+
+}
Modified:
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
===================================================================
---
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-11-13
19:07:16 UTC (rev 5053)
+++
extensions/trunk/archetypes/weld-jsf-minimal-jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-11-13
19:30:41 UTC (rev 5054)
@@ -1,13 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
-
xmlns:h="http://java.sun.com/jsf/html">
-<h:head>
- <title>JSF Demo</title>
-</h:head>
-<h:body>
- <h1>Does Weld Work?</h1>
- <p>My weld-injected bean says <span style="color:
blue;">#{helloWorld.text}</span> in a JSF EL dialect.</p>
- <p>You can write the same value using the Unified EL: <span style="color:
green;">${helloWorld.text}</span></p>
-</h:body>
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:h="http://java.sun.com/jsf/html">
+ <h:head>
+ <title>Weld Starter Application</title>
+ </h:head>
+ <h:body>
+ <h1>Hello World!</h1>
+ <p>My weld-injected bean says <span style="color:
blue;">#{helloWorld.text}</span> in a JSF EL dialect.</p>
+ <p>You can write the same value using the Unified EL: <span
style="color: green;">${helloWorld.text}</span></p>
+
+ <h:form>
+ <h2>Bean Validation examples</h2>
+ <p>Enforces the annotation-based constraints defined on the model
class.</p>
+ <table>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="letters"
value="Letters:"/>
+ </th>
+ <td>
+ <h:inputText id="letters"
value="#{helloWorld.letters}"/>
+ <h:message for="letters" style="color:
red;"/>
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="numbers" value="Numbers (max two
digits):"/>
+ </th>
+ <td>
+ <h:inputText id="numbers"
value="#{helloWorld.numbers}"/>
+ <h:message for="numbers" style="color:
red;"/>
+ </td>
+ </tr>
+ <tr>
+ <th style="text-align: right;">
+ <h:outputLabel for="email" value="Email:"/>
+ </th>
+ <td>
+ <h:inputText id="email"
value="#{helloWorld.email}"/>
+ <h:message for="email" style="color: red;"/>
+ </td>
+ </tr>
+ </table>
+ <p>
+ <h:commandButton action="check" value="Check"/>
+ <h:outputText value=" All clear!"
rendered="#{facesContext.postback and empty facesContext.messageList}"
style="color: green;"/>
+ </p>
+ </h:form>
+ </h:body>
</html>