The Codex of Business Writing Software for Real-World Solutions 2.pptx
Yama quick start english version
1. Yama Quick Start Guide
CHAPTER I
Yama TOOLS
created by Meruvian Education (Eng.version) 1
2. The Purpose
1. Know and understand the tools are needed to run Yama project such as Eclipse IDE,
M2Eclipse, Subclipse, MySQL Query Browser
Learning Material
1.1 Eclipse IDE
Eclipse is an IDE (Integrated Development Software) to develop the software and can
run on all platform (platform independent). The following is characters of Eclipse :
• Multi Platform
Supports development and execution on all the major desktop platforms (Windows,
Mac OS X, Linux, QNX Photon, Pocket PC, HP-UX, AIX, Solaris)
• Multi Language
Eclipse written mostly in Java and can be used to develop applications in Java, but
Eclipse also support with various programming language like C/C++, Cobol, Phyton,
Perl and PHP
• Multi Role
Besides as an IDE for application development, Eclipse can be used for activities in the
software development cycle such as documentation, test software, and web
development
Eclipse is one of the favorite IDE due to free and open source. It means that anyone
can view the programming code of this software. Besides, the advantages that make it
populer is the ability to be developed by users with component named plugin. Kinds of plugin
that available in Eclipse :
created by Meruvian Education (Eng.version) 2
3. – Subversion
– m2eclipse
– Glassfish Integration
– Jboss Tools
– STS (SpringSource Tool Suite)
– EGIT (Git Eclipse Plugin)
– Mercurial Eclipse (Mercurial Eclipse Plugin)
– Windows Builder
1.2 m2eclipse
m2eclipse is a plugin that used if we use Maven as the project management. Maven is
a build tool like Ant but more complex and bigger than Ant. Maven is very good if we build
software that is done by several people
1.3 Subclipse
Subclipse is a plugin that is used for Eclipse integration and Subversion Client.
Subversion (SVN) is an opensource software that useful as version control. Basically, there
are two important parts of SVN. They are SVN Client and SVN Repository. SVN Client is a
software used to access user repository. SVN Repository is a server which contain datas on
the management. Any changes to the data recorded by the SVN repository.
Using this SVN the data in the repository can be copied to the client so that users can
process local data that often called the "Checkout". Then the data at the local when
processed, can be sent back to the repository for version control, and accessible to our
colleagues that usually called "Commit"
created by Meruvian Education (Eng.version) 3
4. 1.4 MySQL Query Browser
A database is a collection of information that is organized so that it can easily be
accessed, managed, and updated. The MySQL Query Browser is a graphical tool provided by
MySQL AB for creating, executing, and optimizing queries in a graphical environment. Where
the http://www.mysql.com/products/administrator/ is designed to administer a MySQL server,
the MySQL Query Browser is designed to help you query and analyze data stored within your
MySQL database
created by Meruvian Education (Eng.version) 4
5. Yama Quick Start Guide
CHAPTER II
TOOLS INSTALLATION
created by Meruvian Education (Eng.version) 5
6. The Purpose
1. Know and understand how to install the tools are needed to run Yama project such as
how to install Eclipse Indigo 3.7, m2eclipse, Subclipse
2. Know and understand how to make a database on MySQL Query Browser
Learning Material
2.1 Eclipse Indigo 3.7 Installation
Eclipse Indigo 3.7 is the latest version that just release last June 2011. Follow the
instruction below to install Eclipse Indigo :
2.1.1 Download Eclipse Indigo from http://www.eclipse.org/downloads/, choose
Eclipse Indigo for Linux 32 bit
created by Meruvian Education (Eng.version) 6
7. 2.1.2 Download that link at Eclipse downloads – mirror selection
2.1.3 Save file in any directory
2.1.4 If the downloaded file is complete, extract the file and run the Eclipse by double
clicking on the Eclipse icon
created by Meruvian Education (Eng.version) 7
8. 2.1.5 Eclipse Indigo will appear and select where you put Eclipse metadata by double
clicking the button Browse
created by Meruvian Education (Eng.version) 8
10. 2.2 M2Eclipse Installation
If previous Cimande we use Ant as the Build Tool, but in Cimande 2.0 we use Maven.
To run this Maven, the Eclipse must be intalled m2eclipse plugin. Follow the instruction below
to install m2eclipse :
2.2.1 To add the m2eclipse update site to the Eclipse site list, choose the menu item
Help → Install New Software
created by Meruvian Education (Eng.version) 10
11. 2.2.2 Click Available Sotware Sites link
2.2.3 Click the Add button to display the Add Site dialog
created by Meruvian Education (Eng.version) 11
12. 2.2.4 Insert the Name field with m2e updates , insert the Location field with the URL
http://download.eclipse.org/technology/m2e/releases , and then click OK, so the new
update site will be added to the list
2.2.5 Check Maven Integration for Eclipse (you can click the disclosure triangle to
see what exactly is included in this feature), then click Next
created by Meruvian Education (Eng.version) 12
13. 2.2.6 View the Install Details, then click Next
2.2.7 Accept the Lisence Agreement and click on the Finish button to download and
install m2eclipse
2.2.8 Restart Eclipse
created by Meruvian Education (Eng.version) 13
14. 2.3 Subclipse Installation
Subclipse installation is needed when we want to check out or commit code to SVN.
Follow the instruction below to install subclipse :
2.3.1 To add the Subclipse update site to the Eclipse site list, choose the menu item
Help → Install New Software
2.3.2 Click Available Software Site link
created by Meruvian Education (Eng.version) 14
15. 2.3.3 Click the Add button to display the Add Site dialog
2.3.4 Insert the Field Name with subclipse, insert the Field Location with the URL for
subclipse update site http://subclipse.tigris.org/update_1.6.x, and then click OK, so the
new update site will be added to the list
2.3.5 Check Subclipse (you can click the disclosure triangle to see what exactly is
included in this feature), then click Next
created by Meruvian Education (Eng.version) 15
16. 2.3.6 View Install Details, then click Next
created by Meruvian Education (Eng.version) 16
17. 2.3.7 Accept Lisence Agreement and click on the Finish button to download and
install subclispe
2.3.8 Restart Eclipse
created by Meruvian Education (Eng.version) 17
18. 2.4 Creating Database
There are several ways to create MySQL database. We can use the command line,
PHP MyAdmin, or use MySQL Query Browser. If we use command line, you must memorize
the syntax to makeaa database. The Syntax is quite simple, CREATE DATABASE
database_name and ends with a semicolon. If you want to use MySQL Query Browser, follow
the instruction how to install and make a database below :
2.5.1 Select System → Administration → Synaptic Package → Manager
2.5.2 Install and download MySQL Query Browser
created by Meruvian Education (Eng.version) 18
19. 2.5.3 To start creating a database, select Application → Programming → MySQL
Query Browser
created by Meruvian Education (Eng.version) 19
20. 2.5.4 Default username : root, password : tulalit
2.5.5 Create database by right click → create schema
created by Meruvian Education (Eng.version) 20
21. Yama Quick Start Guide
CHAPTER III
YAMA CRUD
created by Meruvian Education (Eng.version) 21
22. The Purpose
1. Know and understand Yama overview
2. Know and understand the function using Maven as a Build Tool
3. Know and understand how to create Yama project
4. Know and understand Yama CRUD implementation
Learning Material
3.1 Yama Overview
Yama is a solution category of the various popular frameworks integration. Yama
integration made from SpringMVC that use Hibernate as the ORM (Objeck Relational
Mapping) solution and Velocity as the View. The framework components integrated to be
application integration that have high technology value
3.2 Creating Maven Project
The Build tool that we use to run Yama is Maven. Maven is a build tool like Ant Builder
but more complex. Follow the instruction below to create Maven project :
3.2.1 Open Eclipse Indigo, then change the choice of Java EE to Java
created by Meruvian Education (Eng.version) 22
23. 3.2.2 Select File → New → Other → Maven → Project to create Maven project
3.2.3 Put the Yama project that you will create in any directory, for example in
home/netoya/yama2 by clicking Browse → Next
created by Meruvian Education (Eng.version) 23
24. 3.2.4 At the field Catalog choose All Catalogs then click button Add Archetype and fill
them → Archetype Group Id : org.meruvian.yama
Archetype Artifact Id : yama-archetype
Archetype Version : 1.0-Beta1
Repository URL : https://maven.java.net/content/groups/staging
3.2.5 Create a project package by filling Group Id and Artifact Id. Group Id to fill the
package name and the Artifact Id to fill the project name. For example :
Group Id : org.meruvian
Artifact Id : yama
created by Meruvian Education (Eng.version) 24
25. There are two ways to generate Maven Archetype,using Eclipse or using Console.
If using Console, open Console then go to the directory where you put the
Cimande project and type the code below
mvn archetype:generate
DarchetypeGroupId=org.meruvian.yama
DarchetypeArtifactId=yamaarchetype
DarchetypeVersion=1.0Beta1
DarchetypeRepository=https://maven.java.net/content/groups/staging
DgroupId=org.mycompany
DartifactId=myproject
GroupId to give a package name (e.g : org.meruvian) and ArtifactId to give a
project name (e.g : yama)
created by Meruvian Education (Eng.version) 25
26. 3.2.6 We need database configuration in the package src/main/resources →
applicationContext.html , then customize the database with the name of the database
that you create and customize the password with your MySQL password
3.3 Creating Package
After creating Maven project and import them into Eclipse at the previous chapter, now
we need to create packages as a place where we put the Java class. Create seven packages
in the package org.meruvian. They are entity, form, dao, service, controller, validator, wrapper
3.3.1 Package org.meruvian.yama.entity
This package contains the entity class that used as a link between framework with
the database. Creating table and all the variables that will be displayed in the
database declared here
created by Meruvian Education (Eng.version) 26
27. 3.3.2 Package org.meruvian.yama.form
This package contain class PersonForm.java that used as a container for all the
getter and setter methods from variable that declared in Entity class
3.3.3 Package org.meruvian.yama.dao
Data Access Object (DAO) is an object that provides an abstract interface to a
database or persistence mechanisms and certain operations without showing
details of the database. The Implementation of this concept called separation of
concern, where each code is separated by the function so the code on it only
needs to know abstractly how to access data without knowing how access to data
sources are implemented
3.3.4 Package org.meruvian.yama.service
Service is an object that used to simplify the large code like a library. In the case
of a database we can use the Service to classify some of the DAO in a
transaction
3.3.5 Package org.meruvian.yama.controller
Controller is a layer that works to set the "inter-layer" . This Layer is responsible
for application execution
3.3.6 Package org.meruvian.yama.validator
This package contain class PersonValidator.java that used to validate the data
that must be filled or can not be empty
3.3.7 Package org.meruvian.yama.wrapper
Inside this package there is @XmlRootElement that used to map class into XML
element
created by Meruvian Education (Eng.version) 27
28. 3.4 Creating Java Class
3.4.1 Create class Person.java in the package org.blueoxygen.entity
package org.meruvian.yama.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.hibernate.annotations.GenericGenerator;
/**
* @author vick
*
*/
@Entity
@Table
@XmlRootElement(name = "person")
created by Meruvian Education (Eng.version) 28
29. public class Person implements Serializable {
private static final long serialVersionUID = 203559588950186907L;
@Id
@GeneratedValue(generator = "p")
@GenericGenerator(name = "p", strategy = "uuid")
@Column
private String id;
@Column
private String firstName;
@Column
private String lastName;
@Column
private Boolean gender;
@Column
private Date birthDate;
@Column
private String address;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Boolean getGender() {
return gender;
}
public void setGender(Boolean gender) {
this.gender = gender;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
created by Meruvian Education (Eng.version) 29
30. public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
3.4.2 Create class PersonForm.java in the package org.meruvian.yama.form
package org.meruvian.yama.form;
import java.util.Date;
import org.meruvian.yama.entity.Person;
/**
*
* @author vick
*/
public class PersonForm {
public Person person = new Person();
public PersonForm() {
}
public PersonForm(Person person) {
this person
. = person;
}
public void setPerson(Person person) {
this person
. = person;
}
public Person getPerson() {
return person;
}
public void setId(String id) {
person.setId(id);
}
public String getId() {
return person.getId();
}
public void setFirstName(String firstName) {
person.setFirstName(firstName);
}
public String getFirstName() {
return person.getFirstName();
}
public void setLastName(String lastName) {
person.setLastName(lastName);
}
public String getLastName() {
return person.getLastName();
}
created by Meruvian Education (Eng.version) 30
31. public void setGender(Boolean gender) {
person.setGender(gender);
}
public Boolean getGender() {
return person.getGender();
}
public void setBirthDate(Date birthDate) {
person.setBirthDate(birthDate);
}
public Date getBirthDate() {
return person.getBirthDate();
}
public void setAddress(String address) {
person.setAddress(address);
}
public String getAddress() {
return person.getAddress();
}
}
3.4.3 Create class PersonDao.java in the package org.meruvian.yama.dao
package org.meruvian.yama.dao;
import java.util.List;
import org.meruvian.yama.dao.base.BaseDaoHibernate;
import org.meruvian.yama.entity.Person;
import org.springframework.stereotype.Repository;
/**
*
* @author vick
*/
@Repository
public class PersonDao extends BaseDaoHibernate<Person>{
@SuppressWarnings("unchecked")
public List<Person> listParent(String personId){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id
!= '"+personId+"' and relation_id != '"+personId+"' or relation_id = null ").list();
}
@SuppressWarnings("unchecked")
public List<Person> listChild(String personId, String parentId){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id
!= '"+personId+"' ").list();
}
@SuppressWarnings("unchecked")
public List<Person> listPerson(boolean sex){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where
relation_id = null and gender != "+sex+" ").list();
}
@SuppressWarnings("unchecked")
public List<Person> findPerson(String firstName){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where
created by Meruvian Education (Eng.version) 31
32. firstName like '%"+firstName+"%' ").list();
}
@SuppressWarnings("unchecked")
public List<Person> getParentC(String id){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+" where id
= '"+id+"'").list();
}
@SuppressWarnings("unchecked")
public List<Person> getChildP(String personId, String relationId){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()+"
where parent_id = '"+personId+"' or parent_id = '"+relationId+"' ").list();
}
}
3.4.4 Create class BaseDaoHibernate.java in the package
org.meruvian.yama.dao.base
package org.meruvian.yama.dao.base;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import javax.persistence.PersistenceException;
import org.hibernate.ObjectDeletedException;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* @author vick
*/
public class BaseDaoHibernate<T> {
@SuppressWarnings("unchecked")
protected Class domainClass;
@Autowired protected SessionFactory sessionFactory;
@SuppressWarnings("unchecked")
public BaseDaoHibernate(){
this.domainClass = (Class) ((ParameterizedType)
getClass().getGenericSuperclass()).getActualTypeArguments()[0];
}
@SuppressWarnings("unchecked")
public T findById(String id){
if(id.equalsIgnoreCase("")) return null;
final T domain = (T) sessionFactory.getCurrentSession().get(domainClass, id);
return domain;
}
public T save(T domain){
sessionFactory.getCurrentSession().saveOrUpdate(domain);
return domain;
}
public void delete(T domain){
sessionFactory.getCurrentSession().delete(domain);
}
@SuppressWarnings("unchecked")
created by Meruvian Education (Eng.version) 32
33. public List<T> findAll(Integer startIndex, Integer pageSize){
return sessionFactory.getCurrentSession().createQuery("from
"+domainClass.getName()).setFirstResult(startIndex).setMaxResults(pageSize).list();
}
@SuppressWarnings("unchecked")
public List<T> findAll(){
return sessionFactory.getCurrentSession().createQuery("from "+domainClass.getName()).list();
}
}
3.4.5 Create class PersonService.java in the package org.meruvian.yama.service
package org.meruvian.yama.service;
import java.util.List;
import org.meruvian.yama.entity.Person;
/**
*
* @author vick
*/
public interface PersonService {
void save(Person person);
void delete(Person person);
Person getPerson(String id);
List<Person> getPersons();
List<Person> getPersons(int start, int num);
List<Person> listParents(String personId);
List<Person> listChilds(String personId, String parentId);
List<Person> listPersons(boolean sex);
Person getRelation(String id);
Person getParent(String id);
List<Person> getRelations();
List<Person> getParents(String id);
List<Person> getChilds(String personId, String relationId);
List<Person> findPersons(String firstName);
}
3.4.6 Create class PersonServiceImpl.java in the package
org.meruvian.yama.service.impl
package org.meruvian.yama.service.impl;
import java.util.List;
import org.meruvian.yama.dao.PersonDao;
import org.meruvian.yama.entity.Person;
import org.meruvian.yama.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
*
* @author vick
*/
created by Meruvian Education (Eng.version) 33
34. @Service("personService")
@Transactional(readOnly = true)
public class PersonServiceImpl implements PersonService {
@Autowired
private PersonDao personDao;
@Transactional
public void save(Person person) {
personDao.save(person);
}
@Transactional
public void delete(Person person) {
personDao.delete(person);
}
public Person getPerson(String id){
return personDao.findById(id);
}
public List<Person> getPersons(){
return personDao.findAll();
}
public List<Person> getPersons(int start, int num){
return personDao.findAll(start, num);
}
public Person getRelation(String id){
return personDao.findById(id);
}
public Person getParent(String id){
return personDao.findById(id);
}
public List<Person> getRelations(){
return personDao.findAll();
}
public List<Person> getParents(String id){
return personDao.getParentC(id);
}
public List<Person> getChilds(String personId, String relationId){
return personDao.getChildP(personId, relationId);
}
public List<Person> listParents(String personId){
return personDao.listParent(personId);
}
public List<Person> listChilds(String personId, String parentId){
return personDao.listChild(personId, parentId);
}
public List<Person> listPersons(boolean sex){
return personDao.listPerson(sex);
}
public List<Person> findPersons(String fristName){
return personDao.findPerson(fristName);
}
}
created by Meruvian Education (Eng.version) 34
35. 3.4.7 Create class PersonController.java in the package org.meruvian.yama.controller
package org.meruvian.yama.controller;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.meruvian.yama.entity.Person;
import org.meruvian.yama.form.PersonForm;
import org.meruvian.yama.service.PersonService;
import org.meruvian.yama.validator.PersonValidator;
import org.meruvian.yama.wrapper.PersonListWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
/**
*
* @author vick
*/
@Controller
public class PersonController {
@Autowired
private PersonService personService;
@RequestMapping(value = "/person", method = RequestMethod.GET)
public ModelAndView person(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView();
System.out.println("Person OI");
mv.addObject("person", new Person());
mv.setViewName("person/personadd");
return mv;
}
@RequestMapping(value = "/person", method = RequestMethod.POST)
public ModelAndView person(HttpServletRequest request,
HttpServletResponse response,
@ModelAttribute("person") PersonForm person,
BindingResult bindingResult) {
new PersonValidator().validate(person, bindingResult);
System.out.println("" + person.getBirthDate());
if (bindingResult.hasErrors()) {
ModelAndView mv = new ModelAndView();
mv.addObject("person", person);
mv.setViewName("person/personadd");
return mv;
} else {
personService.save(person.getPerson());
return new ModelAndView(new RedirectView(request.getContextPath()
+ "/person"));
created by Meruvian Education (Eng.version) 35
36. }
}
@RequestMapping(value = "person/listPerson/{sex}", method = RequestMethod.GET)
public ModelAndView personList(HttpServletRequest request,
HttpServletResponse response, @RequestParam("sex") boolean sex)
throws Exception {
List<Person> persons = personService.listPersons(sex);
ModelAndView mv = new ModelAndView("person/personlist");
mv.addObject("list", persons);
return mv;
}
@RequestMapping(value = "/person/search", method = RequestMethod.GET)
public ModelAndView search(HttpServletRequest request,
HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView();
mv.setViewName("person/personsearch");
return mv;
}
@RequestMapping(value = "/person/result", method = RequestMethod.POST)
public ModelAndView builder(@RequestParam("firstName") String firstName) {
StringBuilder builder = new StringBuilder();
builder.append("result");
if (!firstName.equalsIgnoreCase("")) {
builder.append("/" + firstName);
}
ModelAndView mv = new ModelAndView(new RedirectView(builder.toString()));
return mv;
}
@RequestMapping(value = "/person/result/{firstName}", method = RequestMethod.GET)
public ModelAndView result(@PathVariable("firstName") String firstName) {
ModelAndView mv = new ModelAndView();
PersonListWrapper persons = new PersonListWrapper();
persons.setPersons(personService.findPersons(firstName));
mv.addObject("list", persons);
mv.setViewName("person/personresult");
return mv;
}
@RequestMapping(value = "/person/result", method = RequestMethod.GET)
public ModelAndView result(HttpServletRequest request,
HttpServletResponse response) throws Exception {
PersonListWrapper persons = new PersonListWrapper();
persons.setPersons(personService.getPersons());
ModelAndView mv = new ModelAndView("person/personresult");
mv.addObject("list", persons);
return mv;
}
@RequestMapping(value = "/person/{id}/detail", method = RequestMethod.GET)
public ModelAndView detailPerson(@PathVariable("id") String personId) {
Person person = personService.getPerson(personId);
ModelAndView mv = new ModelAndView();
mv.setViewName("person/persondetail");
return mv;
}
@RequestMapping(value = "/person/{id}/edit", method = RequestMethod.GET)
public ModelAndView updatePerson(@PathVariable("id") String personId) {
Person person = personService.getPerson(personId);
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
ModelAndView mv = new ModelAndView();
mv.setViewName("person/personedit");
created by Meruvian Education (Eng.version) 36
37. mv.addObject("person", person);
return mv;
}
@RequestMapping(value = "/person/{id}/edit", method = RequestMethod.POST)
public ModelAndView updatePerson(HttpServletRequest request,
@ModelAttribute("person") PersonForm person,
BindingResult bindingResult) {
new PersonValidator().validate(person, bindingResult);
if (bindingResult.hasErrors()) {
ModelAndView mv = new ModelAndView();
mv.addObject("person", person);
mv.setViewName("person/personedit");
return mv;
} else {
personService.save(person.getPerson());
return new ModelAndView(new RedirectView(request.getContextPath()
+ "/person/result"));
}
}
@RequestMapping(value = "/person/{id}/delete", method = RequestMethod.GET)
public ModelAndView deletePerson(HttpServletRequest request,
@PathVariable("id") String personId) {
Person person = personService.getPerson(personId);
personService.delete(person);
return new ModelAndView(new RedirectView(request.getContextPath()
+ "/person/result"));
}
}
3.4.8 Create class Index.java in the package org.meruvian.yama.controller
package org.meruvian.yama.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
/**
* @author vick
*
*/
@Controller
public class Index {
@RequestMapping(value="/",method=RequestMethod.GET)
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
return new ModelAndView(new RedirectView(request.getContextPath()+"/person"));
}
}
3.4.9 Create class PersonValidator.java in the package org.meruvian.yama.validator
package org.meruvian.yama.validator;
import org.meruvian.yama.form.PersonForm;
created by Meruvian Education (Eng.version) 37
38. import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;
/**
*
* @author vick
*/
public class PersonValidator implements Validator{
public boolean supports(Class<?> clazz){
return PersonForm.class.equals(clazz);
}
public void validate(Object val, Errors errors){
ValidationUtils.rejectIfEmpty(errors, "firstName", "firstName.empty");
ValidationUtils.rejectIfEmpty(errors, "lastName", "lastName.empty");
ValidationUtils.rejectIfEmpty(errors, "gender", "gender.empty");
}
}
3.4.10 Create class PersonListWrapper.java in the package org.meruvian.yama.wrapper
package org.meruvian.yama.wrapper;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.meruvian.yama.entity.Person;
/**
* @author vick
*
*/
@XmlRootElement(name = "personListWrapper")
public class PersonListWrapper {
private List<Person> persons;
public List<Person> getPersons() {
return persons;
}
public void setPersons(List<Person> persons) {
this.persons = persons;
}
}
3.5 Creating View
Creating code for the View that stored in the package /src/main/webapp/WEB-
INF/velocity/person
created by Meruvian Education (Eng.version) 38
46. 3.7 Running Yama Project
To run the Yama project and generate the database we use Maven build by right click
Yama project → Run As → Maven Build and use command tomcat:run to run the server
3.9 Yama CRUD
Open web browser then enter URL http://localhost:8080/yama/ to run Yama CRUD
3.9.1 CREATE
PERSON-ADD form contain input field to fill First Name, Last Name, Sex, Birth
Date and Address. First Name, Last Name dan Sex as the validation data
created by Meruvian Education (Eng.version) 46
48. 3.9.2 SEARCH
to search for data, click Search at the top ADD PERSON form
created by Meruvian Education (Eng.version) 48
49. 3.9.3 DETAIL
There are three actions at the PERSON RESULT form. They are Detail, Update
and Delete.The picture below is the form that will launch when detail action clicked
3.9.4 UPDATE
3.9.5 DELETE
When the Delete icon is clicked, automatically the data will be deleted directly
created by Meruvian Education (Eng.version) 49