Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_pt
CreateActions
CreateActions_de
SpringControllers_ko
ValidationAndList_pt




JSPWiki v2.2.33

[RSS]


Hide Menu

ValidationAndList


Difference between version 29 and version 28:

At line 13 changed 2 lines.
* [3] Add ''testGetPersons'' methods to DAO and Manager Tests
* [4] Add ''getPersons'' methods to DAO and Manager Interfaces and Implementation classes
* [3] Add ''testGetPeople'' methods to DAO and Manager Tests
At line 91 changed 1 line.
* validate="true" parameter="action" input="editPerson.do?action=Edit"
* validate="true" parameter="action" input="edit"
At line 125 changed 2 lines.
!!Add testGetPersons methods to DAO and Manager Tests [#3]
To create a List screen (also called a master screen), we need to create methods that will return all the rows from our ''person'' table. Let's start by adding tests for these methods to our PersonDaoTest and PersonManagerTest classes. I usually name this method ''getEntities'' (i.e. getPersons), but you could also use ''getAll'' or ''search'' - it's really just a matter of personal preference.
!!Add testGetPeople methods to DAO and Manager Tests [#3]
To create a List screen (also called a master screen), we need to create methods that will return all the rows from our ''person'' table. Let's start by adding tests for these methods to our PersonDaoTest and PersonManagerTest classes. I usually name this method ''getEntities'' (i.e. getUsers), but you could also use ''getAll'' or ''search'' - it's really just a matter of personal preference.
At line 128 changed 1 line.
Open test/dao/**/persistence/PersonDaoTest.java and add a ''testGetPersons'' method:
Open test/dao/**/persistence/PersonDaoTest.java and add a ''testGetPeople'' method:
At line 132 changed 1 line.
public void testGetPersons() throws Exception {
public void testGetPeople() {
At line 134 changed 1 line.
List results = dao.getPersons(person);
List results = dao.getPeople(person);
At line 139 changed 1 line.
The reason I'm passing in a person object to the ''getPersons'' method is to allow for filtering (based on values in person) in the future.
The reason I'm passing in a person object to the ''getPeople'' method is to allow for filtering (based on values in person) in the future.
At line 141 changed 1 line.
Now open test/service/**/service/PersonManagerTest.java and add a ''testGetPersons'' method:
Now open test/service/**/service/PersonManagerTest.java and add a ''testGetPeople'' method:
At line 145 changed 3 lines.
public void testGetPersons() throws Exception {
//personForm = new PersonForm();
List results = mgr.getPersons(person); //Form);
public void testGetPeople() {
List results = mgr.getPeople(new Person());
At line 152 changed 1 line.
Neither of these classes will compile at this point since the ''getPersons'' method does not exist on our Interfaces (PersonDao and PersonManager), not on our Implementations (PersonDaoHibernate and PersonManagerImpl). Let's giddyup and add those suckers.
Save all your files and make sure everything compiles with __ant clean compile__. Now you should be able to run both tests by running the following:
At line 154 removed 47 lines.
!!Add getPersons methods to DAO and Manager Interfaces and Implementation classes [#4]
First, let's modify our interfaces to include a ''getPersons'' method. Open src/dao/**/persistence/PersonDao.java and add the following:
;:''You will need to import java.util.List in each of these interfaces. In Eclipse, Ctrl+Shift+O is the fastest way.''
[{Java2HtmlPlugin
public List getPersons(Person person) throws DAOException;
}]
Then, open src/service/**/service/PersonManager.java and add a similar method:
[{Java2HtmlPlugin
public List getPersons(Object person) throws Exception;
}]
Now we need to add the implementation (a.k.a. "the meat") for these methods into our DAO and Manager implementations. Open src/dao/**/persistence/PersonDaoHibernate.java and add the following method:
;:%%(color: blue)''I looked in UserDAOHibernate.java and used the getUsers method as a template for getPersons.''
[{Java2HtmlPlugin
/**
* @see org.appfuse.persistence.PersonDao#getPersons(org.appfuse.model.Person)
*/
public List getPersons(Person person) throws DAOException {
return getHibernateTemplate().find("from Person p order by upper(p.firstName)");
}
}]
You'll notice here that we're doing nothing with the ''person'' parameter. This is just a placeholder for now - in the future you may want to filter on it's properties using [Hibernate's Query Language|http://www.hibernate.org/hib_docs/reference/html/query-language.html] (HQL) or using [Criteria Queries|http://www.hibernate.org/hib_docs/reference/html/query-criteria.html].
Also, add a ''getPersons'' method to src/service/**/service/PersonManagerImpl.java:
[{Java2HtmlPlugin
/**
* @see org.appfuse.webapp.service.PersonManager#getPersons(java.lang.Object)
*/
public List getPersons(Object obj) throws Exception {
return dao.getPersons((Person) person);
}
}]
Save all your files and make sure everything compiles with __ant clean package-web__. Now you should be able to run both tests by running the following:

Back to ValidationAndList, or to the Page History.