Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

default project structure, validations and some css

  • Loading branch information...
commit a8837c14cfbad5a82daa66996df1a8d5e37f08fe 1 parent 723b878
@ceci ceci authored ceci committed
View
3  .classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="owner.project.facets" value="java"/>
View
3  .settings/org.eclipse.wst.common.component
@@ -2,8 +2,9 @@
<project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="agilebr-inscricoes">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
- <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/test"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<property name="context-root" value="agilebr-inscricoes"/>
<property name="java-output-path" value="/agilebr-inscricoes/build/classes"/>
</wb-module>
View
3  WebContent/META-INF/MANIFEST.MF
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Class-Path:
-
View
14 WebContent/WEB-INF/jsp/attendees/create.jsp
@@ -0,0 +1,14 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%@ page language="java" contentType="text/html; charset=UTF-8"
+ pageEncoding="UTF-8"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Agile Brazil - Inscrições</title>
+</head>
+<body>
+ <fmt:message key="attendee.created" />
+</body>
+</html>
View
34 WebContent/WEB-INF/jsp/attendees/index.jsp
@@ -1,23 +1,32 @@
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Agile Brazil - Inscrições</title>
<link href="<c:url value='/css/html5forms.layout.css'/>" rel="stylesheet" />
<link href="<c:url value='/css/jquery.ui.all.css' />" rel="stylesheet" />
+ <link href="<c:url value='/css/agilebrazil.css' />" rel="stylesheet" />
+ <script src="<c:url value='/js/jquery-1.4.3.min.js' />"></script>
<script src="<c:url value='/js/jquery-ui-1.8.5.min.js' />"></script>
</head>
<body>
- <form action="create">
- <label for="firstName">Nome</label> <input name="attendee.firstName" id="firstName" /><br />
+ <div id="errors">
+ <c:forEach var="error" items="${errors}">
+ <fmt:message key="${error.message }" />
+ </c:forEach>
+ </div>
+
+ <form action="create" method="POST">
+ <label for="firstName"><fmt:message key="attendee.firstName" /></label> <input name="attendee.firstName" id="firstName" /><br />
<label for="lastName">Sobrenome</label> <input name="attendee.lastName" id="lastName" /><br />
<label for="badgeName">Nome para o crachá</label> <input name="attendee.badgeName" id="badgeName"/><br />
<label for="gender">Sexo</label> <input name="attendee.gender" id="gender" /><br />
<label for="email">Email</label> <input name="attendee.email" id="email" /><br />
- <label for="emailConfirmation">Confirme o email</label> <input name="emailConfirmation" id="emailConfirmation" /><br />
+ <label for="emailConfirmation">Confirme o email</label> <input name="emailConfirmation" class="required" id="emailConfirmation" /><br />
<label for="twitter">Twitter</label> <input name="attendee.twitter" id="twitter" /><br />
<label for="organization">Empresa</label> <input name="attendee.organization" id="organization" /><br />
<label for="phone">Telefone de contato</label> <input name="attendee.phone" id="phone" /><br />
@@ -25,7 +34,11 @@
<label for="zipcode">CEP</label> <input name="attendee.zipcode" id="zipcode" /><br />
<label for="neighbourhood">Bairro</label> <input name="attendee.neighbourhood" id="neighbourhood" /><br />
<label for="city">Cidade</label> <input name="attendee.city" id="city" /><br />
- <label for="state">Estado</label> <input name="attendee.state" id="state" /><br />
+ <label for="state">Estado</label> <select name="attendee.state" id="state">
+ <c:forEach var="state" items="${states }">
+ <option value="${state.name }">${state.name }</option>
+ </c:forEach>
+ </select><br />
<label for="country">País</label> <input name="attendee.country" id="country" /><br />
<button class="ui-button ui-button-text-only" type="submit">
@@ -33,5 +46,16 @@
</button>
</form>
+ <script type="text/javascript">
+ var confirmation = $("#emailConfirmation");
+ confirmation.blur(function() {
+ if (confirmation.val() != $("#email").val()) {
+ confirmation.css({background: "#FFBBBB"});
+ } else {
+ confirmation.css({background: "#FFFFFF"});
+ }
+ });
+ </script>
+
</body>
</html>
View
BIN  WebContent/WEB-INF/lib/hibernate-validator-3.1.0.GA.jar
Binary file not shown
View
6 WebContent/WEB-INF/web.xml
@@ -15,4 +15,10 @@
br.com.caelum.vraptor.util.jpa
</param-value>
</context-param>
+
+ <context-param>
+ <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
+ <param-value>messages</param-value>
+ </context-param>
+
</web-app>
View
9 WebContent/css/agilebrazil.css
@@ -0,0 +1,9 @@
+@CHARSET "UTF-8";
+
+#errors {
+ margin: 0px auto 10px;
+ padding: 5px;
+ background: #FFBBBB;
+ text-align: center;
+ border: 2px dashed #FF9999;
+}
View
31 src/br/com/agilebrazil/inscricoes/controllers/AttendeesController.java
@@ -1,31 +0,0 @@
-package br.com.agilebrazil.inscricoes.controllers;
-
-import br.com.agilebrazil.inscricoes.dao.AttendeeDAO;
-import br.com.agilebrazil.inscricoes.model.Attendee;
-import br.com.caelum.vraptor.Get;
-import br.com.caelum.vraptor.Resource;
-
-@Resource
-public class AttendeesController {
-
-
- private final AttendeeDAO attendeeDAO;
-
-
- public AttendeesController(AttendeeDAO attendeeDAO) {
- this.attendeeDAO = attendeeDAO;
-
- }
-
- public void index(){
-
- }
-
- @Get
- public void create(Attendee attendee){
- if(attendeeDAO.doesntExist(attendee)){
- attendeeDAO.save(attendee);
- }
- }
-
-}
View
43 src/main/java/br/com/agilebrazil/inscricoes/controllers/AttendeesController.java
@@ -0,0 +1,43 @@
+package br.com.agilebrazil.inscricoes.controllers;
+
+import br.com.agilebrazil.inscricoes.dao.AttendeeDAO;
+import br.com.agilebrazil.inscricoes.model.Attendee;
+import br.com.agilebrazil.inscricoes.model.State;
+import br.com.caelum.vraptor.Post;
+import br.com.caelum.vraptor.Resource;
+import br.com.caelum.vraptor.Result;
+import br.com.caelum.vraptor.Validator;
+import br.com.caelum.vraptor.validator.ValidationMessage;
+
+@Resource
+public class AttendeesController {
+
+
+ private final AttendeeDAO dao;
+ private final Result result;
+ private final Validator validator;
+
+
+ public AttendeesController(Result result, Validator validator, AttendeeDAO attendeeDAO) {
+ this.result = result;
+ this.validator = validator;
+ this.dao = attendeeDAO;
+ }
+
+ public void index(){
+ result.include("states", State.values());
+ }
+
+ @Post
+ public void create(Attendee attendee, String emailConfirmation){
+ validator.validate(attendee);
+ if (attendee.getEmail().equals(emailConfirmation))
+ validator.add(new ValidationMessage("email.confirmation", "attendee"));
+ if(dao.alreadyExists(attendee)){
+ validator.add(new ValidationMessage("already.registered", "attendee"));
+ }
+ validator.onErrorForwardTo(this).index();
+ dao.save(attendee);
+ }
+
+}
View
6 ...ilebrazil/inscricoes/dao/AttendeeDAO.java → ...ilebrazil/inscricoes/dao/AttendeeDAO.java
@@ -4,7 +4,6 @@
import javax.persistence.EntityManager;
import javax.persistence.Query;
-import javax.persistence.TypedQuery;
import br.com.agilebrazil.inscricoes.model.Attendee;
import br.com.caelum.vraptor.ioc.Component;
@@ -19,13 +18,14 @@ public AttendeeDAO(EntityManager em) {
}
- public boolean doesntExist(Attendee attendee) {
+ @SuppressWarnings("unchecked")
+ public boolean alreadyExists(Attendee attendee) {
String jpql = "select attendee from Attendee attendee where attendee.email =:email";
Query query = em.createQuery(jpql);
query.setParameter("email", attendee.getEmail());
List<Attendee> result = query.getResultList();
- return result.size()==0;
+ return result.size()!=0;
}
public void save(Attendee attendee) {
View
28 ...gilebrazil/inscricoes/model/Attendee.java → ...gilebrazil/inscricoes/model/Attendee.java
@@ -1,9 +1,13 @@
package br.com.agilebrazil.inscricoes.model;
import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
+import org.hibernate.validator.NotEmpty;
+
import br.com.caelum.vraptor.ioc.Component;
@Component
@@ -14,10 +18,15 @@
@GeneratedValue
private Long id;
+ @NotEmpty
private String email;
+ @NotEmpty
private String firstName;
+
+ @NotEmpty
private String lastName;
+
private String gender;
private String badgeName;
private String organization;
@@ -25,10 +34,18 @@
private String address;
private String neighbourhood;
private String zipcode;
+
+ @NotEmpty
private String phone;
- private String country;
- private String state;
+
+ @NotEmpty
private String city;
+
+ @Enumerated(EnumType.STRING)
+ private State state;
+
+ @NotEmpty
+ private String country;
public Long getId() {
return id;
@@ -63,6 +80,9 @@ public void setLastName(String lastName) {
}
public String getBadgeName() {
+ if (badgeName == null) {
+ badgeName = firstName + " " + lastName;
+ }
return badgeName;
}
@@ -126,11 +146,11 @@ public void setCountry(String country) {
this.country = country;
}
- public String getState() {
+ public State getState() {
return state;
}
- public void setState(String state) {
+ public void setState(State state) {
this.state = state;
}
View
10 src/main/java/br/com/agilebrazil/inscricoes/model/State.java
@@ -0,0 +1,10 @@
+package br.com.agilebrazil.inscricoes.model;
+
+public enum State {
+
+ SP, NOT_APPLICABLE;
+
+ public String getName() {
+ return name();
+ }
+}
View
2  src/META-INF/persistence.xml → src/main/resources/META-INF/persistence.xml
@@ -8,7 +8,7 @@
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
- <property name="hibernate.hbm2ddl.auto" value="update"/>
+ <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
View
7 src/main/resources/messages.properties
@@ -0,0 +1,7 @@
+#Errors
+already.registered = E-mail j&aacute; cadastrado
+email.confirmation = E-mail n&atilde;o bate com confirma&ccedil;&atilde;o
+
+#Attendee
+attendee.created=Cadastrado com sucesso!
+attendee.firstName = Nome
View
7 src/main/resources/messages_en.properties
@@ -0,0 +1,7 @@
+#Errors
+already.registered = E-mail already in use
+email.confirmation = E-mail and confirmation don't match
+
+#Attendee
+attendee.created=Successfully created
+attendee.firstName = First name
Please sign in to comment.
Something went wrong with that request. Please try again.