inject service dao tapestry5

Buat Tabel di mysql:

 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;

Buat bean Laptop:

 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;
 }

}

buat interface LaptopDao.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);

}

buat class LaptopDaoImpl.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);
 }

}

tambahkan setting AppModule.java untuk inject service dao

public static void bind(ServiceBinder binder)
 {
 binder.bind(LaptopDao.class, LaptopDaoImpl.class);
 binder.bind(MasterFacade.class);
 }

buat MasterLaptop.tml

 <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>

buat MasterLaptop.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";
 }
 }

minum kopi klo udah selesai😀

sambil nunggu jetty running di server😀

Published by

saifiahmada

Begin a big Process with a bit trying

One thought on “inject service dao tapestry5”

  1. Excellent sharing knowledge, could you kindly share some of XML configuration as well as download source code.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s