Display country name in persons list; implementation to be enhanced. Also, 
moved all TODOs and SUBTASKs to PersonAction.java; these are temporary comments.


Project: http://git-wip-us.apache.org/repos/asf/struts-examples/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts-examples/commit/78becd73
Tree: http://git-wip-us.apache.org/repos/asf/struts-examples/tree/78becd73
Diff: http://git-wip-us.apache.org/repos/asf/struts-examples/diff/78becd73

Branch: refs/heads/master
Commit: 78becd730d4acb24189c42c7d542015bd089125c
Parents: 21bcfe6
Author: Antonio Sánchez <ads...@gmail.com>
Authored: Fri May 2 17:12:54 2014 +0200
Committer: Antonio Sánchez <ads...@gmail.com>
Committed: Fri May 2 17:12:54 2014 +0200

----------------------------------------------------------------------
 .../apache/struts/crud/action/PersonAction.java | 10 ++++++-
 .../apache/struts/crud/dao/MemoryPersonDao.java | 12 ++++----
 .../struts/crud/dao/MemoryPersonSupportDao.java |  9 ++++--
 .../org/apache/struts/crud/dao/PersonDao.java   |  4 ++-
 .../struts/crud/dao/PersonSupportDao.java       |  4 ++-
 .../org/apache/struts/crud/model/Country.java   | 30 ++++++++++++++------
 .../org/apache/struts/crud/model/Person.java    | 16 +++++------
 .../struts/crud/service/PersonService.java      |  4 ++-
 .../crud/action/PersonAction-validation.xml     |  1 -
 .../struts/crud/action/PersonAction.properties  |  4 +--
 crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp |  3 +-
 crud/src/main/webapp/WEB-INF/jsp/persons.jsp    | 15 ++++++----
 12 files changed, 72 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/action/PersonAction.java
----------------------------------------------------------------------
diff --git a/crud/src/main/java/org/apache/struts/crud/action/PersonAction.java 
b/crud/src/main/java/org/apache/struts/crud/action/PersonAction.java
index 6096be8..2b7bd5f 100755
--- a/crud/src/main/java/org/apache/struts/crud/action/PersonAction.java
+++ b/crud/src/main/java/org/apache/struts/crud/action/PersonAction.java
@@ -15,7 +15,15 @@ import org.apache.struts.crud.service.PersonService;
  * TODO display country name instead of code
  * TODO logging
  * TODO prepareInput 
- *
+ * TODO I18e messages in validation.xml
+ * TODO use templates for patterns: X is required... Person... in properties 
file
+ * TODO I18e all static text in jsps
+ * 
+ * SUBTASK I18e database text data
+ * SUBTASK Definitely, improve 'country' data implementation
+ * SUBTASK add jetty and tomcat plugins to pom.xml
+ * SUBTASK look & feel like that of showcase applications; enhance 
visualization
+ * 
  * @author bruce phillips
  * @author antonio sánchez
  */

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonDao.java
----------------------------------------------------------------------
diff --git a/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonDao.java 
b/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonDao.java
index 5bc2576..c1888bd 100755
--- a/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonDao.java
+++ b/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonDao.java
@@ -5,7 +5,9 @@ import java.util.List;
 import org.apache.struts.crud.model.Person;
 
 /**
- *In memory data repository for Person objects.
+ * In memory data repository for Person objects.
+ * 
+ * @author bruce phillips
  * @author antonio sanchez
  */
 public class MemoryPersonDao implements PersonDao {
@@ -14,8 +16,8 @@ public class MemoryPersonDao implements PersonDao {
 
     static {
         persons = new ArrayList<>();
-        persons.add(new Person(1, "Bruce", "Phillips", "basketball", "male", 
"US", true, new String[]{"Ford", "Nissan"}, "bphill...@ku.edu", 
"123-456-9999"));
-        persons.add(new Person(2, "Antonio", "Sanchez", "mtb", "male", "ES", 
true, new String[]{"Toyota", "Seat"}, "asanc...@correoe.es", "555-999-8888"));
+        persons.add(new Person(1, "Bruce", "Phillips", "basketball", "male", 
MemoryPersonSupportDao.getCountry("US"), true, new String[]{"Ford", "Nissan"}, 
"bphill...@ku.edu", "123-456-9999"));
+        persons.add(new Person(2, "Antonio", "Sanchez", "mtb", "male", 
MemoryPersonSupportDao.getCountry("ES"), true, new String[]{"Toyota", "Seat"}, 
"asanc...@correo-e.es", "555-999-8888"));
     }
 
     @Override
@@ -39,7 +41,7 @@ public class MemoryPersonDao implements PersonDao {
         for (int i = 0; i < persons.size(); i++) {
             Person p = persons.get(i);
             if (p.getPersonId().equals(id)) {
-//                
person.setDepartment(departmentsMap.get(person.getDepartment().getDepartmentId()));
+                
person.setCountry(MemoryPersonSupportDao.getCountry(person.getCountry().getCountryId()));
                 persons.set(i, person);
                 break;
             }
@@ -54,8 +56,8 @@ public class MemoryPersonDao implements PersonDao {
                 lastId = p.getPersonId();
             }
         }
-//        
person.setDepartment(departmentsMap.get(person.getDepartment().getDepartmentId()));
         person.setPersonId(lastId + 1);
+        
person.setCountry(MemoryPersonSupportDao.getCountry(person.getCountry().getCountryId()));
         persons.add(person);
     }
 

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonSupportDao.java
----------------------------------------------------------------------
diff --git 
a/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonSupportDao.java 
b/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonSupportDao.java
index 429ff47..580a116 100755
--- a/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonSupportDao.java
+++ b/crud/src/main/java/org/apache/struts/crud/dao/MemoryPersonSupportDao.java
@@ -5,8 +5,7 @@ import java.util.Map;
 import org.apache.struts.crud.model.Country;
 
 /**
- * TODO I18e database text data
- * 
+ * @author bruce phillips
  * @author antonio sanchez
  */
 public class MemoryPersonSupportDao implements PersonSupportDao {
@@ -25,7 +24,7 @@ public class MemoryPersonSupportDao implements 
PersonSupportDao {
         
         countriesMap = new HashMap<>();
         for (Country c : countries) {
-            countriesMap.put(c.getCountryAbbr(), c);
+            countriesMap.put(c.getCountryId(), c);
         }
     }
 
@@ -50,4 +49,8 @@ public class MemoryPersonSupportDao implements 
PersonSupportDao {
     public Country[] getCountries() {
         return countries;
     }
+    
+    static Country getCountry(String countryId) {
+        return countriesMap.get(countryId);
+    }
 }

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/dao/PersonDao.java
----------------------------------------------------------------------
diff --git a/crud/src/main/java/org/apache/struts/crud/dao/PersonDao.java 
b/crud/src/main/java/org/apache/struts/crud/dao/PersonDao.java
index 79ace0e..e371dd1 100755
--- a/crud/src/main/java/org/apache/struts/crud/dao/PersonDao.java
+++ b/crud/src/main/java/org/apache/struts/crud/dao/PersonDao.java
@@ -6,7 +6,9 @@ import org.apache.struts.crud.model.Person;
  * Data access methods that a PersonDao class
  * must define to provide information about
  * a Person or collection of Person objects.
- * @author antonio sanchez
+ * 
+ * @author bruce phillips
+ * @author antonio sánchez
  */
 public interface PersonDao {
     

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/dao/PersonSupportDao.java
----------------------------------------------------------------------
diff --git 
a/crud/src/main/java/org/apache/struts/crud/dao/PersonSupportDao.java 
b/crud/src/main/java/org/apache/struts/crud/dao/PersonSupportDao.java
index 2a38bc6..4a2489c 100755
--- a/crud/src/main/java/org/apache/struts/crud/dao/PersonSupportDao.java
+++ b/crud/src/main/java/org/apache/struts/crud/dao/PersonSupportDao.java
@@ -6,7 +6,9 @@ import org.apache.struts.crud.model.Country;
 /**
  * Methods a PersonSupportDao class must implement to provide
  * additional information related to a Person.
- * @author antonio sanchez
+ * 
+ * @author bruce phillips
+ * @author antonio sánchez
  */
 public interface PersonSupportDao {
 

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/model/Country.java
----------------------------------------------------------------------
diff --git a/crud/src/main/java/org/apache/struts/crud/model/Country.java 
b/crud/src/main/java/org/apache/struts/crud/model/Country.java
index b8289bb..7e39daa 100755
--- a/crud/src/main/java/org/apache/struts/crud/model/Country.java
+++ b/crud/src/main/java/org/apache/struts/crud/model/Country.java
@@ -3,23 +3,27 @@ package org.apache.struts.crud.model;
 /**
  * Model a country.
  * 
+ * @author bruce phillips
  * @author antonio sánchez
  */
 public class Country {
-    private String countryAbbr;
+    private String countryId;
     private String countryName;
 
-    public Country(String countryAbbr, String countryName) {
-        this.countryAbbr = countryAbbr;
-        this.countryName = countryName;
+    public Country(String countryId, String countryName) {
+        setCountryId(countryId);
+        setCountryName(countryName);
     }
 
-    public void setCountryAbbr(String countryAbbr) {
-        this.countryAbbr = countryAbbr;
+    public void setCountryId(String countryId) {
+        if (countryId == null)
+            throw new IllegalArgumentException("Country ID must be non-null.");
+        
+        this.countryId = countryId;
     }
 
-    public String getCountryAbbr() {
-        return countryAbbr;
+    public String getCountryId() {
+        return countryId;
     }
 
     public void setCountryName(String countryName) {
@@ -32,6 +36,14 @@ public class Country {
 
     @Override
     public String toString() {
-        return getCountryAbbr();
+        return getCountryId();
+    }
+    
+    @Override
+    public boolean equals(Object o) {
+        return (o!=null) 
+                && (o instanceof Country) 
+                && (((Country) o).getCountryId() != null) 
+                && (countryId.equals(((Country) o).getCountryId()));
     }
 }

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/model/Person.java
----------------------------------------------------------------------
diff --git a/crud/src/main/java/org/apache/struts/crud/model/Person.java 
b/crud/src/main/java/org/apache/struts/crud/model/Person.java
index ebb9e93..8dd4a92 100755
--- a/crud/src/main/java/org/apache/struts/crud/model/Person.java
+++ b/crud/src/main/java/org/apache/struts/crud/model/Person.java
@@ -14,7 +14,7 @@ public class Person {
     private String lastName;
     private String sport;
     private String gender;
-    private String residency;
+    private Country country = new Country("", "");
     private boolean over21;
     private String[] carModels;
     private String email;
@@ -25,14 +25,14 @@ public class Person {
     }
     
     public Person(Integer id, String firstName, String lastName, String sport, 
-                String gender, String residency, boolean over21, String[] 
carModels, 
+                String gender, Country country, boolean over21, String[] 
carModels, 
                 String email, String phoneNumber) {
         this.personId = id;
         this.firstName = firstName;
         this.lastName = lastName;
         this.sport = sport;
         this.gender = gender;
-        this.residency = residency;
+        this.country = country;
         this.over21 = over21;
         this.carModels = carModels;
         this.email = email;
@@ -79,12 +79,12 @@ public class Person {
         return gender;
     }
 
-    public void setResidency(String residency) {
-        this.residency = residency;
+    public void setCountry(Country country) {
+        this.country = country;
     }
 
-    public String getResidency() {
-        return residency;
+    public Country getCountry() {
+        return country;
     }
 
     public void setOver21(boolean over21) {
@@ -126,7 +126,7 @@ public class Person {
                 + " Last Name:  " + getLastName() + " | "
                 + " Favorite Sport: " + getSport() + " | "
                 + " Gender: " + getGender() + " | "
-                + " Residency: " + getResidency() + " | "
+                + " Country: " + getCountry() + " | "
                 + " Over 21: " + isOver21() + " | "
                 + " Car models: " + Arrays.asList(getCarModels()) + " | "
                 + " Email: " + getEmail() + " | "

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/java/org/apache/struts/crud/service/PersonService.java
----------------------------------------------------------------------
diff --git 
a/crud/src/main/java/org/apache/struts/crud/service/PersonService.java 
b/crud/src/main/java/org/apache/struts/crud/service/PersonService.java
index bc369ba..bbd1ee4 100755
--- a/crud/src/main/java/org/apache/struts/crud/service/PersonService.java
+++ b/crud/src/main/java/org/apache/struts/crud/service/PersonService.java
@@ -6,7 +6,9 @@ import org.apache.struts.crud.model.Person;
 /**
  * Define methods a PersonService must implement
  * to provide services related to a Person class.
- * @author bphillips
+ * 
+ * @author bruce phillips
+ * @author antonio sánchez
  */
 public interface PersonService {
 

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/resources/org/apache/struts/crud/action/PersonAction-validation.xml
----------------------------------------------------------------------
diff --git 
a/crud/src/main/resources/org/apache/struts/crud/action/PersonAction-validation.xml
 
b/crud/src/main/resources/org/apache/struts/crud/action/PersonAction-validation.xml
index 8a147a6..8497431 100755
--- 
a/crud/src/main/resources/org/apache/struts/crud/action/PersonAction-validation.xml
+++ 
b/crud/src/main/resources/org/apache/struts/crud/action/PersonAction-validation.xml
@@ -1,7 +1,6 @@
 <!DOCTYPE validators PUBLIC
          "-//Apache Struts//XWork Validator 1.0.3//EN"
            "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd";>
-<!-- TODO I18e messages -->           
 <validators>
     <validator type="requiredstring">
         <param name="fieldname">person.firstName</param>

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/resources/org/apache/struts/crud/action/PersonAction.properties
----------------------------------------------------------------------
diff --git 
a/crud/src/main/resources/org/apache/struts/crud/action/PersonAction.properties 
b/crud/src/main/resources/org/apache/struts/crud/action/PersonAction.properties
index 5c58085..9215803 100755
--- 
a/crud/src/main/resources/org/apache/struts/crud/action/PersonAction.properties
+++ 
b/crud/src/main/resources/org/apache/struts/crud/action/PersonAction.properties
@@ -1,12 +1,10 @@
-#TODO use templates for patterns: X is required... Person...
-
 person.firstName=First name
 person.lastName=Last name
 person.email=Email address
 person.phoneNumber=Phone number (999-999-9999)
 person.sport=Favorite sport
 person.gender=Gender
-person.residency=State resident
+person.country=Country
 person.over21=21 or older
 person.carModels=Car models owned
 

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp
----------------------------------------------------------------------
diff --git a/crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp 
b/crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp
index 8480a4a..9bce092 100755
--- a/crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp
+++ b/crud/src/main/webapp/WEB-INF/jsp/editPerson.jsp
@@ -1,4 +1,3 @@
-<%-- TODO I18e all static text --%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" 
pageEncoding="UTF-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <s:if test="person==null || person.personId == null">
@@ -27,7 +26,7 @@
             <s:textfield key="person.phoneNumber" />
             <s:select key="person.sport" list="sports" />
             <s:radio key="person.gender" list="genders" />
-            <s:select key="person.residency" list="countries" 
listKey="countryAbbr" listValue="countryName" />
+            <s:select name="person.country.countryId" list="countries" 
listKey="countryId" listValue="countryName" 
label="%{getText('person.country')}"/>
             <s:checkbox key="person.over21" />
             <s:checkboxlist key="person.carModels" list="carModelsAvailable" />
             

http://git-wip-us.apache.org/repos/asf/struts-examples/blob/78becd73/crud/src/main/webapp/WEB-INF/jsp/persons.jsp
----------------------------------------------------------------------
diff --git a/crud/src/main/webapp/WEB-INF/jsp/persons.jsp 
b/crud/src/main/webapp/WEB-INF/jsp/persons.jsp
index 94f9fcb..4acce5b 100755
--- a/crud/src/main/webapp/WEB-INF/jsp/persons.jsp
+++ b/crud/src/main/webapp/WEB-INF/jsp/persons.jsp
@@ -1,5 +1,3 @@
-<%-- TODO I18e all static text --%>
-<%-- TODO Simplify table header texts  --%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" 
pageEncoding="UTF-8"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
@@ -23,7 +21,7 @@
                 <th><s:text name="person.phoneNumber"/></th>
                 <th><s:text name="person.sport"/></th>
                 <th><s:text name="person.gender"/></th>
-                <th><s:text name="person.residency"/></th>
+                <th><s:text name="person.country"/></th>
                 <th><s:text name="person.over21"/></th>
                 <th><s:text name="person.carModels"/></th>
                 <th>&nbsp;</th>
@@ -36,8 +34,15 @@
                     <td class="nowrap"><s:property value="phoneNumber"/></td>
                     <td class="nowrap"><s:property value="sport"/></td>
                     <td class="nowrap"><s:property value="gender"/></td>
-                    <td class="nowrap"><s:property value="residency"/></td>
-                    <td class="nowrap"><s:property value="over21"/></td>
+                    <td class="nowrap"><s:property 
value="country.countryName"/></td>
+                    <td class="nowrap">
+                        <s:if test="over21">
+                            <span style="color:green; font-size: 
large;">&#x2714;</span>
+                        </s:if>
+                        <s:else>
+                            <span style="color:red; font-size: 
large;">&#x2717;</span>
+                        </s:else>                        
+                    </td>
                     <td class="nowrap"><s:property value="carModels"/></td>
                     <td class="nowrap">
                         <s:url action="inputPerson" id="url">

Reply via email to