Hoaahmm,, setelah kemarin bikin tampilan awal menggunakan SOA sekarang kita bikin Create, Read, Update dan Delete nya. Biar pas astu paket gitu.. 
Caranya masih sama, kalo udah baca blog sebelumnya maka anda pasti ngerti. Tapi kita nggak perlu buat WebClient. Jadi kita hanya perlu membuat controller dkk.
Pertama, kita buat Controller nya dulu. Beri nama CustomerAddController (untuk create nya), CustomerEditController (untuk edit nya), CustomerDetilController(untuk view nya)dan CustomerDeleteController (untuk deletenya). Caranya masih sama Klik kanan pada Source Package - > New - > Java class, pilih project yang sudah ada. Kalau masih belum ada beri nama project sesuai dengan kapasitas memori anda?biar ntar gak gampang lupa ?-.
Setelah itu kita masukkan codingan2 kita,, hehe
Untuk yang CustomerAddController, ini codingannya, jangan sampe keliru yaaa
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.customer.controller;
import com.customer.ws.Customer;
import com.customer.ws.CustomerWs;
import com.customer.ws.CustomerWsService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/**
*
* @author user
*/
public class CustomerAddController extends MultiActionController{
public ModelAndView customeradd(HttpServletRequest arg0, HttpServletResponse arg1, Customer customer) throws Exception {
ModelMap modelMap = new ModelMap();
modelMap.addAttribute(new Customer());
String action = arg0.getParameter("action"
== null ? "" : arg0.getParameter("action"
;
if (action.equalsIgnoreCase("1"
) {
CustomerWsService service = new CustomerWsService();
CustomerWs port = service.getCustomerWsPort();
System.out.println(">>>cek customer.getFirstname() :" + customer.getFirstname());
System.out.println(">>>cek customer.getLastname() :" + customer.getLastname());
System.out.println(">>>cek customer.getAge() :" + customer.getAge());
port.create(customer);
return new ModelAndView("redirect:customerlist.htm"
;
} else {
return new ModelAndView("customeradd", modelMap);
}
}
}
Ini buat yang CustomerEditController,,
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.customer.controller;
import com.customer.ws.Customer;
import com.customer.ws.CustomerWs;
import com.customer.ws.CustomerWsService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/**
*
* @author user
*/
public class CustomerEditController extends MultiActionController{
public ModelAndView customeredit(HttpServletRequest arg0, HttpServletResponse arg1, Customer customer) throws Exception {
CustomerWsService service = new CustomerWsService();
CustomerWs port = service.getCustomerWsPort();
ModelAndView mav = new ModelAndView();
String action = arg0.getParameter("action"
==null?"":arg0.getParameter("action"
;
if(action.equalsIgnoreCase("1"
){
System.out.println(">>>cek customer.getId() :" + customer.getId());
System.out.println(">>>cek customer.getFirstname() :" + customer.getFirstname());
System.out.println(">>>cek customer.getLastname() :" + customer.getLastname());
System.out.println(">>>cek customer.getAge() :" + customer.getAge());
port.edit(customer);
return new ModelAndView("redirect:customerlist.htm"
;
} else {
Integer id = Integer.parseInt(arg0.getParameter("customerid"
);
customer = port.find(id);
mav.addObject("customer", customer);
return mav;
}
}
}
Ini yang CustomerDeleteController,,
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.customer.controller;
import com.customer.ws.Customer;
import com.customer.ws.CustomerWs;
import com.customer.ws.CustomerWsService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/**
*
* @author user
*/
public class CustomerDeleteController extends MultiActionController{
public ModelAndView customerdelete(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
CustomerWsService service = new CustomerWsService();
CustomerWs port = service.getCustomerWsPort();
Customer customer = port.find(Integer.parseInt(arg0.getParameter("customerid"
));
port.remove(customer);
return new ModelAndView("redirect:customerlist.htm"
;
}
}
Finally CustomerDetilControllernya,,
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.customer.controller;
import com.customer.ws.Customer;
import com.customer.ws.CustomerWs;
import com.customer.ws.CustomerWsService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/**
*
* @author user
*/
public class CustomerDetilController extends MultiActionController{
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest arg0, HttpServletResponse arg1) throws Exception {
Integer customerId = Integer.parseInt(arg0.getParameter("customerid"
);
CustomerWsService service = new CustomerWsService();
CustomerWs port = service.getCustomerWsPort();
Customer customer = port.find(customerId);
System.out.println(">>>customer size: " + customer.getFirstname());
ModelAndView mav = new ModelAndView();
mav.addObject("customer", customer);
return mav;
}
}
Setelah buat Controller nya kita buat view nya di JSP, ini yang customeradd yaa?.
<%--
Document : customeradd
Created on : Jan 18, 2010, 11:32:58 PM
Author : user
--%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Customer</title>
</head>
<body>
<h2>Customer Add</h2>
<form:form action="customeradd.htm?action=1" commandName="customer">
<table border="1" width="100%">
<tr>
<td>Firstname</td>
<td>:</td>
<td><form:input path="firstname" /></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><form:input path="lastname" /></td>
</tr>
<tr>
<td>Age</td>
<td>:</td>
<td><form:input path="age" /></td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Add" /></td>
</tr>
</table>
</form:form>
<div>
<a href="customerlist.htm">Customer List</a>
<br/>
</div>
</body>
</html>
ini yang customeredit.jsp nya,, Nah untuk kelanjutannya Insya Allah saya post lagi minggu depan,,
<%--
Document : customeredit
Created on : Jan 18, 2010, 11:32:58 PM
Author : user
--%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Customer</title>
</head>
<body>
<h2>Customer Edit</h2>
<form:form action="customeredit.htm?action=1" commandName="customer">
<table border="1" width="100%">
<tr>
<td>Firstname</td>
<td>:</td>
<td><form:input path="firstname" /></td>
<form:hidden path="id"/>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>