[sourcecode language="sql"]
create table laptop
(
id_laptop varchar(15) primary key not null,
label varchar(30) not null,
merk varchar(30),
cpu varchar(30),
memory varchar(30),
speed varchar(30),
harddisk varchar(30),
webcam varchar(30)
) ENGINE=InnoDB;
[/sourcecode]
Buat bean Laptop:
[sourcecode language="java"]
package com.ipi.mysms.beans;
import org.apache.tapestry5.beaneditor.NonVisual;
public class Laptop {
@NonVisual
private String id_laptop;
private String label;
private String merk;
private String cpu;
private String memory;
private String speed;
private String harddisk;
private String webcam;
public String getId_laptop() {
return id_laptop;
}
public void setId_laptop(String id_laptop) {
this.id_laptop = id_laptop;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getMerk() {
return merk;
}
public void setMerk(String merk) {
this.merk = merk;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public String getMemory() {
return memory;
}
public void setMemory(String memory) {
this.memory = memory;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
public String getHarddisk() {
return harddisk;
}
public void setHarddisk(String harddisk) {
this.harddisk = harddisk;
}
public String getWebcam() {
return webcam;
}
public void setWebcam(String webcam) {
this.webcam = webcam;
}
}
[/sourcecode]
buat interface LaptopDao.java
[sourcecode language="java"]
package com.ipi.mysms.dao;
import java.util.List;
import com.ipi.mysms.beans.Laptop;
public interface LaptopDao {
public void insert(Laptop laptop);
public void update(Laptop laptop);
public void delete(Laptop laptop);
public List<Laptop> getAllLaptop();
public Laptop findByPrimaryKey(String id_laptop);
}
[/sourcecode]
buat class LaptopDaoImpl.java
[sourcecode language="java"]
package com.ipi.mysms.daoimpl;
import java.util.List;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.ipi.mysms.beans.Laptop;
import com.ipi.mysms.dao.LaptopDao;
public class LaptopDaoImpl extends SqlMapClientDaoSupport implements LaptopDao {
public void insert(Laptop laptop) {
getSqlMapClientTemplate().insert("Laptop.insert", laptop);
}
public void update(Laptop laptop) {
getSqlMapClientTemplate().update("Laptop.update", laptop);
}
public void delete(Laptop laptop) {
getSqlMapClientTemplate().delete("Laptop.delete", laptop);
}
public List<Laptop> getAllLaptop() {
return getSqlMapClientTemplate().queryForList("Laptop.getAllLaptop");
}
public Laptop findByPrimaryKey(String id_laptop) {
return (Laptop) getSqlMapClientTemplate().queryForObject("Laptop.findByPrimaryKey", id_laptop);
}
}
[/sourcecode]
tambahkan setting AppModule.java untuk inject service dao
[sourcecode language="java"]
public static void bind(ServiceBinder binder)
{
binder.bind(LaptopDao.class, LaptopDaoImpl.class);
binder.bind(MasterFacade.class);
}
[/sourcecode]
buat MasterLaptop.tml
[sourcecode language="xml"]
<html t:type="cetakan" title="Master Contact"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">
<t:form>
<fieldset><legend>Master Laptop</legend>
<t:errors/>
<div>
<t:beaneditor t:id="laptop" t:object="laptop">
</t:beaneditor><br/>
<div>
<t:submit t:id="save" t:value="Save/Update"/>
<t:submit t:id="reset" t:value="Reset"/>
<t:submit t:id="search" t:value="Search"/>
<t:submit t:id="delete" t:value="Delete"/>
</div>
</div>
</fieldset>
<t:grid source="listlaptop" row="laptoprow" add="del" reorder="del" rowsperpage="6" rowClass="${evenodd}" pagerPotition="top">
<t:parameter name="delcell">
<t:checkbox t:id="del" t:value="del"/>
</t:parameter>
<t:parameter name="labelcell">
<t:actionlink t:id="edit" context="laptoprow.id_laptop">${laptoprow.label}</t:actionlink>
</t:parameter>
</t:grid>
</t:form>
</html>
[/sourcecode]
buat MasterLaptop.java
[sourcecode language="java"]
package com.ipi.mysms.pages.master;
import java.util.ArrayList;
import java.util.List;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import com.ipi.mysms.beans.Laptop;
import com.ipi.mysms.dao.LaptopDao;
import com.ipi.mysms.facade.MasterFacade;
import com.ipi.mysms.util.Generate;
public class MasterLaptop {
@Inject
private LaptopDao laptopDao;
@Inject
private MasterFacade masterFacate;
@Persist
private Laptop laptop;
@Property
private Laptop laptoprow;
private List<Laptop> listLaptop;
private boolean del;
private List<Laptop> listDelete;
void clear(){
laptop = new Laptop();
}
void onSelectedFromSave(){
if (getLaptop().getId_laptop() == null){
getLaptop().setId_laptop(Generate.getId());
laptopDao.insert(getLaptop());
}else{
laptopDao.update(getLaptop());
}
clear();
}
void onSelectedFromReset(){
clear();
}
void onSelectedFromDelete(){
for (Laptop l : getListDelete()){
laptopDao.delete(l);
}
clear();
}
void onSelecetedFromSearch(){
}
void onActionFromEdit(String id_laptop){
Laptop l = laptopDao.findByPrimaryKey(id_laptop);
setLaptop(l);
}
public List<Laptop> getListLaptop(){
if (listLaptop == null) listLaptop = new ArrayList<Laptop>();
return laptopDao.getAllLaptop();
}
public Laptop getLaptop() {
if (laptop == null) laptop = new Laptop();
return laptop;
}
public void setLaptop(Laptop laptop) {
this.laptop = laptop;
}
public boolean isDel() {
return del;
}
public void setDel(boolean del) {
if (del){
getListDelete().add(laptoprow);
}
}
public List<Laptop> getListDelete() {
if (listDelete == null) listDelete = new ArrayList<Laptop>();
return listDelete;
}
public void setListDelete(List<Laptop> listDelete) {
this.listDelete = listDelete;
}
private int i = 0;
public String getEvenOdd(){
i++;
return i % 2 == 0 ? "odd" : "even";
}
}
[/sourcecode]
minum kopi klo udah selesai :D
sambil nunggu jetty running di server :D
Excellent sharing knowledge, could you kindly share some of XML configuration as well as download source code.
ReplyDelete