master kecamatan tapestry 5

MasterKecamatan.tml

<html t:type="cetakan" title="Master Kecamatan"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">

<t:form>
<fieldset><legend>Master Kecamatan</legend>

<t:errors/>
<div>
<t:beaneditor t:id="kecamatan" t:object="kecamatan">
<t:parameter name="id_kabupaten">
<t:label for="id_kabupaten"/><t:select t:id="id_kabupaten" model="modelkabupaten" value="kecamatan.id_kabupaten"/>
</t:parameter>

</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="listkecamatan" row="kecamatanrow" add="del" t:volatile="true" reorder="del,kode_kecamatan,nama_kecamatan,id_kabupaten" rowsperpage="25" rowClass="${evenodd}" pagerPotition="top">
<t:parameter name="delcell">
<t:checkbox t:id="del" t:value="del"/>
</t:parameter>
<t:parameter name="nama_kecamatancell">
<t:actionlink t:id="edit" context="kecamatanrow.id_kecamatan">${kecamatanrow.nama_kecamatan}</t:actionlink>
</t:parameter>
<t:parameter name="id_kabupatencell">
${kecamatanrow.kabupaten.nama_kabupaten}
</t:parameter>
</t:grid>

</t:form>
</html>

MasterKecamatan.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 com.ipi.mysms.base.BasePage;
import com.ipi.mysms.beans.Kecamatan;
import com.ipi.mysms.util.Generate;
import com.ipi.mysms.util.ModelFactory;

public class MasterKecamatan extends BasePage {

@Persist
private Kecamatan kecamatan;

@Persist
private Kecamatan kec;

@Property
private Kecamatan kecamatanrow;

private List<Kecamatan> listKecamatan;

private boolean del;

private List<Kecamatan> listDelete;

private ModelFactory modelKabupaten;

void onSelectedFromSave(){
if (getKecamatan().getId_kecamatan() == null){
getKecamatan().setId_kecamatan(Generate.getId());
getMasterFacade().getKecamatanDao().insert(getKecamatan());
}else{
getMasterFacade().getKecamatanDao().update(getKecamatan());
}
clear();
}

void onSelectedFromReset(){
clear();
}

void onSelectedFromSearch(){
setKec(getKecamatan());
}

void onSelectedFromDelete(){
for (Kecamatan k : getListDelete()){
getMasterFacade().getKecamatanDao().delete(k);
}
clear();
}

void clear(){
kecamatan = new Kecamatan();
kec = new Kecamatan();
}

void onActionFromEdit(String id_kecamatan){
Kecamatan k = getMasterFacade().getKecamatanDao().findByPrimaryKey(id_kecamatan);
setKecamatan(k);
}

private int i = 0;
public String getevenOdd(){
i++;
return i % 2 == 0 ? "odd" : "even";
}

public Kecamatan getKecamatan() {
if (kecamatan == null) kecamatan = new Kecamatan();
return kecamatan;
}

public void setKecamatan(Kecamatan kecamatan) {
this.kecamatan = kecamatan;
}

public List<Kecamatan> getListKecamatan() {
listKecamatan = getMasterFacade().getKecamatanDao().getKecamatanByFilter(getKec());
if (listKecamatan == null) listKecamatan = new ArrayList<Kecamatan>();
return listKecamatan;
}

public void setListKecamatan(List<Kecamatan> listKecamatan) {
this.listKecamatan = listKecamatan;
}

public boolean isDel() {
return del;
}

public void setDel(boolean del) {
if (del){
getListDelete().add(kecamatanrow);
}
}

public List<Kecamatan> getListDelete() {
if (listDelete == null) listDelete = new ArrayList<Kecamatan>();
return listDelete;
}

public void setListDelete(List<Kecamatan> listDelete) {
this.listDelete = listDelete;
}

public ModelFactory getModelKabupaten(){
List list = getMasterFacade().getKabupatenDao().getMapAllKabupaten();
modelKabupaten = new ModelFactory(list, "nama_kabupaten", "id_kabupaten");
return modelKabupaten;
}

public Kecamatan getKec() {
return kec;
}

public void setKec(Kecamatan kec) {
this.kec = kec;
}




}
 

Kecamatan.java

package com.ipi.mysms.beans;

import org.apache.tapestry5.beaneditor.NonVisual;

public class Kecamatan {

@NonVisual
private String id_kecamatan;

private String id_kabupaten;

private String kode_kecamatan;

private String nama_kecamatan;

private Kabupaten kabupaten;

public String getId_kecamatan() {
return id_kecamatan;
}

public void setId_kecamatan(String id_kecamatan) {
this.id_kecamatan = id_kecamatan;
}

public String getId_kabupaten() {
return id_kabupaten;
}

public void setId_kabupaten(String id_kabupaten) {
this.id_kabupaten = id_kabupaten;
}

public String getKode_kecamatan() {
return kode_kecamatan;
}

public void setKode_kecamatan(String kode_kecamatan) {
this.kode_kecamatan = kode_kecamatan;
}

public String getNama_kecamatan() {
return nama_kecamatan;
}

public void setNama_kecamatan(String nama_kecamatan) {
this.nama_kecamatan = nama_kecamatan;
}

public Kabupaten getKabupaten() {
return kabupaten;
}

public void setKabupaten(Kabupaten kabupaten) {
this.kabupaten = kabupaten;
}



}
 

ScreenShot:

Advertisements

master kabupaten tapestry 5

MasterKabupaten.tml

<html t:type="cetakan" title="Master Kabupaten"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">

<t:form>
<fieldset><legend>Master Kabupaten</legend>

<t:errors/>
<div>
<t:beaneditor t:id="kabupaten" t:object="kabupaten">
<t:parameter name="id_propinsi">
<t:label for="id_propinsi"/><t:select t:id="id_propinsi" t:model="modelpropinsi" t:value="kabupaten.id_propinsi"/>
</t:parameter>
</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="listkabupaten" row="kabupatenrow" add="del" reorder="del,kode_kabupaten,nama_kabupaten,ibu_kota,id_propinsi" rowsperpage="25" rowClass="${evenodd}" pagerPotition="top" t:volatile="true">
<t:parameter name="delcell">
<t:checkbox t:id="del" t:value="del"/>
</t:parameter>
<t:parameter name="nama_kabupatencell">
<t:actionlink t:id="edit" context="kabupatenrow.id_kabupaten">${kabupatenrow.nama_kabupaten}</t:actionlink>
</t:parameter>

<t:parameter name="id_propinsicell">
${kabupatenrow.propinsi.nama_propinsi}
</t:parameter>
</t:grid>

</t:form>
</html>

MasterKabupaten.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 org.apache.tapestry5.ioc.services.PropertyAccess;

import com.ipi.mysms.beans.Kabupaten;
import com.ipi.mysms.beans.Propinsi;
import com.ipi.mysms.util.Generate;
import com.ipi.mysms.util.GenericSelectModel;
import com.sun.tools.javac.jvm.Gen;

public class MasterKabupaten extends com.ipi.mysms.base.BasePage{

@Persist
private Kabupaten kabupaten;

@Persist
@Property
private Kabupaten kab;

@Property
private Kabupaten kabupatenrow;

private List<Kabupaten> listKabupaten;

private boolean del;

private List<Kabupaten> listDelete;

@Inject
private PropertyAccess access;

void onSelectedFromSave(){
if (getKabupaten().getId_kabupaten() == null){
getKabupaten().setId_kabupaten(Generate.getId());
getMasterFacade().getKabupatenDao().insert(getKabupaten());
}else{
getMasterFacade().getKabupatenDao().update(getKabupaten());
}
clear();
}

void onSelectedFromReset(){
clear();
}

void onSelectedFromSearch(){
kab = getKabupaten();
}

void onSelectedFromDelete(){
for (Kabupaten k : getListDelete()){
getMasterFacade().getKabupatenDao().delete(k);
}
}

void onActionFromEdit(String id_kabupaten){
Kabupaten k = getMasterFacade().getKabupatenDao().findByPrimaryKey(id_kabupaten);
setKabupaten(k);
}

void clear(){
kabupaten = new Kabupaten();
kab = new Kabupaten();
}

private int i = 0;
public String getEvenOdd(){
i++;
return i % 2 == 0 ? "odd" : "even";
}

public Kabupaten getKabupaten() {
if (kabupaten == null) kabupaten = new Kabupaten();
return kabupaten;
}

public void setKabupaten(Kabupaten kabupaten) {
this.kabupaten = kabupaten;
}

public List<Kabupaten> getListKabupaten() {
listKabupaten = getMasterFacade().getKabupatenDao().getKabupatenByFilter(kab);
if (listKabupaten == null) listKabupaten = new ArrayList<Kabupaten>();
return listKabupaten;
}

public void setListKabupaten(List<Kabupaten> listKabupaten) {
this.listKabupaten = listKabupaten;
}

public boolean isDel() {
return del;
}

public void setDel(boolean del) {
if (del ){
getListDelete().add(kabupatenrow);
}
}

public List<Kabupaten> getListDelete() {
if (listDelete == null) listDelete = new ArrayList<Kabupaten>();
return listDelete;
}

public void setListDelete(List<Kabupaten> listDelete) {
this.listDelete = listDelete;
}

public String getModelPropinsi(){
StringBuffer sb = new StringBuffer();
List<Propinsi> list = getMasterFacade().getPropinsiDao().getAllPropinsi();
int i = list.size();
int j = 0;
for (Propinsi p : list){
j++;
sb.append(p.getId_propinsi()+"="+p.getNama_propinsi());
if (j < i){
sb.append(",");
}
}
return sb.toString();
}

}

Kabupaten.java

 package com.ipi.mysms.beans;

import org.apache.tapestry5.beaneditor.NonVisual;

public class Kabupaten {

@NonVisual
private String id_kabupaten;

private String id_propinsi;

private String kode_kabupaten;

private String nama_kabupaten;

private String ibu_kota;

private Propinsi propinsi;

public String getId_kabupaten() {
return id_kabupaten;
}

public void setId_kabupaten(String id_kabupaten) {
this.id_kabupaten = id_kabupaten;
}

public String getId_propinsi() {
return id_propinsi;
}

public void setId_propinsi(String id_propinsi) {
this.id_propinsi = id_propinsi;
}

public String getKode_kabupaten() {
return kode_kabupaten;
}

public void setKode_kabupaten(String kode_kabupaten) {
this.kode_kabupaten = kode_kabupaten;
}

public String getNama_kabupaten() {
return nama_kabupaten;
}

public void setNama_kabupaten(String nama_kabupaten) {
this.nama_kabupaten = nama_kabupaten;
}

public String getIbu_kota() {
return ibu_kota;
}

public void setIbu_kota(String ibu_kota) {
this.ibu_kota = ibu_kota;
}

public Propinsi getPropinsi() {
return propinsi;
}

public void setPropinsi(Propinsi propinsi) {
this.propinsi = propinsi;
}

}

property model pada komponen select tapestry 5

Buat sebuah class yang implements interface “org.apache.tapestry5.util.AbstractSelectModel”

package com.ipi.mysms.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.internal.OptionModelImpl;
import org.apache.tapestry5.util.AbstractSelectModel;

import com.ipi.mysms.config.ResultSetMap;

public class ModelFactory extends AbstractSelectModel {

private List<OptionModel> options;

private List list;

private String label;

private String id;

public ModelFactory(List list, String label, String id) {
this.list = list;
this.label = label;
this.id = id;
}

public List<OptionGroupModel> getOptionGroups() {
return null;
}

public List<OptionModel> getOptions() {
options =  new ArrayList<OptionModel>();
for (int i = 0 ; i < list.size() ; i++){
ResultSetMap rs = (ResultSetMap) list.get(i);

options.add(new OptionModelImpl((String) rs.get(label),rs.get(id)));
}
return options;
}

}

Buat template

<html t:type="cetakan" title="Master Kecamatan"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">

<t:form>
<fieldset><legend>Master Kecamatan</legend>

<t:errors/>
<div>
<t:beaneditor t:id="kecamatan" t:object="kecamatan">
<t:parameter name="id_kabupaten">
<t:label for="id_kabupaten"/><t:select t:id="id_kabupaten" model="modelkabupaten" value="kecamatan.id_kabupaten"/>
</t:parameter>

</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="listkecamatan" row="kecamatanrow" add="del" reorder="del,kode_kecamatan,nama_kecamatan,id_kabupaten" rowsperpage="6" rowClass="${evenodd}" pagerPotition="top">
<t:parameter name="delcell">
<t:checkbox t:id="del" t:value="del"/>
</t:parameter>
<t:parameter name="nama_kecamatancell">
<t:actionlink t:id="edit" context="kecamatanrow.id_kecamatan">${kecamatanrow.nama_kecamatan}</t:actionlink>
</t:parameter>
<t:parameter name="id_kabupatencell">
${kecamatanrow.kabupaten.nama_kabupaten}
</t:parameter>
</t:grid>

</t:form>
</html>

Dan file 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 com.ipi.mysms.base.BasePage;
import com.ipi.mysms.beans.Kecamatan;
import com.ipi.mysms.util.Generate;
import com.ipi.mysms.util.ModelFactory;

public class MasterKecamatan extends BasePage {

@Persist
private Kecamatan kecamatan;

@Property
private Kecamatan kecamatanrow;

private List<Kecamatan> listKecamatan;

private boolean del;

private List<Kecamatan> listDelete;

private ModelFactory modelKabupaten;

void onSelectedFromSave(){
if (getKecamatan().getId_kecamatan() == null){
getKecamatan().setId_kecamatan(Generate.getId());
getMasterFacade().getKecamatanDao().insert(getKecamatan());
}else{
getMasterFacade().getKecamatanDao().update(getKecamatan());
}
clear();
}

void onSelectedFromReset(){
clear();
}

void onSelectedFromSearch(){

}

void onSelectedFromDelete(){

}

void clear(){
kecamatan = new Kecamatan();
}

void onActionFromEdit(String id_kecamatan){
Kecamatan k = getMasterFacade().getKecamatanDao().findByPrimaryKey(id_kecamatan);
setKecamatan(k);
}

private int i = 0;
public String getevenOdd(){
i++;
return i % 2 == 0 ? "odd" : "even";
}

public Kecamatan getKecamatan() {
if (kecamatan == null) kecamatan = new Kecamatan();
return kecamatan;
}

public void setKecamatan(Kecamatan kecamatan) {
this.kecamatan = kecamatan;
}

public List<Kecamatan> getListKecamatan() {
listKecamatan = getMasterFacade().getKecamatanDao().getAllKecamatan();
if (listKecamatan == null) listKecamatan = new ArrayList<Kecamatan>();
return listKecamatan;
}

public void setListKecamatan(List<Kecamatan> listKecamatan) {
this.listKecamatan = listKecamatan;
}

public boolean isDel() {
return del;
}

public void setDel(boolean del) {
if (del){
getListDelete().add(kecamatanrow);
}
}

public List<Kecamatan> getListDelete() {
if (listDelete == null) listDelete = new ArrayList<Kecamatan>();
return listDelete;
}

public void setListDelete(List<Kecamatan> listDelete) {
this.listDelete = listDelete;
}

public ModelFactory getModelKabupaten(){
List list = getMasterFacade().getKabupatenDao().getMapAllKabupaten();
modelKabupaten = new ModelFactory(list, "nama_kabupaten", "id_kabupaten");
return modelKabupaten;
}


}

Hasil 😀

master facade perpusq

MasterFacade.java

package com.ipi.myweb.facade;

import com.ipi.myweb.dao.AnggotaDao;
import com.ipi.myweb.dao.BukuDao;
import com.ipi.myweb.dao.InstitusiDao;
import com.ipi.myweb.dao.KategoriDao;
import com.ipi.myweb.dao.KonfigurasiDao;
import com.ipi.myweb.dao.PenerbitDao;
import com.ipi.myweb.dao.PengembalianDao;
import com.ipi.myweb.dao.PinjamDao;
import com.ipi.myweb.dao.RakDao;
import com.ipi.myweb.dao.UserDao;

public class MasterFacade {

private BukuDao bukuDao;

private AnggotaDao anggotaDao;

private RakDao rakDao;

private KategoriDao kategoriDao;

private PenerbitDao penerbitDao;

private PinjamDao pinjamDao;

private PengembalianDao pengembalianDao;

private UserDao userDao;

private InstitusiDao institusiDao;

private KonfigurasiDao konfigurasiDao;

public BukuDao getBukuDao() {
return bukuDao;
}

public void setBukuDao(BukuDao bukuDao) {
this.bukuDao = bukuDao;
}

public AnggotaDao getAnggotaDao() {
return anggotaDao;
}

public void setAnggotaDao(AnggotaDao anggotaDao) {
this.anggotaDao = anggotaDao;
}

public RakDao getRakDao() {
return rakDao;
}

public void setRakDao(RakDao rakDao) {
this.rakDao = rakDao;
}

public KategoriDao getKategoriDao() {
return kategoriDao;
}

public void setKategoriDao(KategoriDao kategoriDao) {
this.kategoriDao = kategoriDao;
}

public PenerbitDao getPenerbitDao() {
return penerbitDao;
}

public void setPenerbitDao(PenerbitDao penerbitDao) {
this.penerbitDao = penerbitDao;
}

public PinjamDao getPinjamDao() {
return pinjamDao;
}

public void setPinjamDao(PinjamDao pinjamDao) {
this.pinjamDao = pinjamDao;
}

public PengembalianDao getPengembalianDao() {
return pengembalianDao;
}

public void setPengembalianDao(PengembalianDao pengembalianDao) {
this.pengembalianDao = pengembalianDao;
}

public UserDao getUserDao() {
return userDao;
}

public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}

public InstitusiDao getInstitusiDao() {
return institusiDao;
}

public void setInstitusiDao(InstitusiDao institusiDao) {
this.institusiDao = institusiDao;
}

public KonfigurasiDao getKonfigurasiDao() {
return konfigurasiDao;
}

public void setKonfigurasiDao(KonfigurasiDao konfigurasiDao) {
this.konfigurasiDao = konfigurasiDao;
}

}

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 😀

crud dengan beaneditor tapestry5

File-file yang dibuat
MasterUser.tml
MasterUser.java
User.java
Role.java

Untuk MasterUser.tml :

<html     t:type="cetakan" title="Master User"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<t:form>
 <fieldset><legend>Master User</legend>

<t:errors/>
 <div>

<t:beaneditor t:id="user" object="user"/>
 <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="listUser" row="userrow" add="del" reorder="del">
 <t:parameter name="delcell">
 <t:checkbox t:id="del" t:value="del"/>
 </t:parameter>
 <t:parameter name="usernamecell">
 <t:actionlink t:id="edit" context="userrow.id_user">${userrow.username}</t:actionlink>
 </t:parameter>
 </t:grid>
 </t:form>

</html>

Sedangkan untuk MasterUser.java :

package com.example.tutorial.pages.master;

import java.util.ArrayList;
 import java.util.List;

import org.apache.tapestry5.annotations.Persist;
 import org.apache.tapestry5.annotations.Property;

import com.example.tutorial.entities.User;
 import com.example.tutorial.util.TutorialUtil;

public class MasterUser {

@Property
 private User userRow;
 @Persist
 private User user;

private boolean del;

private List<User> listDelete;

private List<User> listUser = new ArrayList<User>();

void onSelectedFromSave(){
 if (getUser().getId_user() == null){
 getUser().setId_user(TutorialUtil.getId());
 getListUser().add(getUser());
 }else{

}
 clear();
 }

void onSelectedFromReset(){
 clear();
 }

void onSelectedFromDelete(){
 for(User u : getListDelete()){
 getListUser().remove(u);
 }

}

void onSelectedFromSearch(){

}

void onActionFromEdit(String id_user){
 User u = new User();
 for (User usr : getListUser()){
 if (usr.getId_user().equals(id_user))
 u = usr;
 }
 setUser(u);
 }

void clear(){
 user = new User();
 }

public User getUser() {
 if (user == null) user = new User();
 return user;
 }

public void setUser(User user) {
 this.user = user;
 }

public List<User> getListUser() {
 return listUser;
 }

public void setListUser(List<User> listUser) {
 this.listUser = listUser;
 }

public boolean isDel() {
 return del;
 }

public void setDel(boolean del) {
 if (del){
 getListDelete().add(userRow);
 }
 }

public List<User> getListDelete() {
 if (listDelete == null) listDelete = new ArrayList<User>();
 return listDelete;
 }

public void setListDelete(List<User> listDelete) {
 this.listDelete = listDelete;
 }

}

Sedangkan untuk User.java :

package com.example.tutorial.entities;

import org.apache.tapestry5.beaneditor.NonVisual;

public class User {

@NonVisual
 private String id_user;

private String username;

private String password;

private Role role;

private boolean active;

private java.util.Date beginDate;

private java.util.Date expiredDate;

public String getId_user() {
 return id_user;
 }

public void setId_user(String id_user) {
 this.id_user = id_user;
 }

public String getUsername() {
 return username;
 }

public void setUsername(String username) {
 this.username = username;
 }

public String getPassword() {
 return password;
 }

public void setPassword(String password) {
 this.password = password;
 }

public Role getRole() {
 return role;
 }

public void setRole(Role role) {
 this.role = role;
 }

public boolean isActive() {
 return active;
 }

public void setActive(boolean active) {
 this.active = active;
 }

public java.util.Date getBeginDate() {
 return beginDate;
 }

public void setBeginDate(java.util.Date beginDate) {
 this.beginDate = beginDate;
 }

public java.util.Date getExpiredDate() {
 return expiredDate;
 }

public void setExpiredDate(java.util.Date expiredDate) {
 this.expiredDate = expiredDate;
 }

}

dan Role.java :

package com.example.tutorial.entities;

public enum Role {
 ADMIN, USER
 }

WAL HASHIL

menggunakan beaneditform dan grid tapestry5

File-file yang dibuat :

MasterPasien.tml

MasterPasien.java

Pasien.java

Gender.java

Gol_Darah.java

Untuk MasterPasien.tml

<html     t:type="cetakan" title="Master Pasien"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<fieldset><legend>Master Pasien</legend>
 <t:beaneditform t:id="pasien">

</t:beaneditform><t:actionlink t:id="reset">Reset</t:actionlink>
 </fieldset>

<t:grid source="listpasien" row="pasienrow">
 <t:parameter name="namacell">
 <t:actionlink t:id="edit" context="pasienrow.id_pasien">${pasienrow.nama}</t:actionlink>
 </t:parameter>
 </t:grid>
 </html>

Sedangkan file MasterPasien.java

package com.example.tutorial.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.annotations.SetupRender;

import com.example.tutorial.entities.Pasien;
 import com.example.tutorial.util.TutorialUtil;

public class MasterPasien {

@Persist
 private Pasien pasien;

private Pasien pasienrow;

private List<Pasien> listPasien = new ArrayList<Pasien>();

@SetupRender
 void setupRender(){
 if (pasien == null) pasien = new Pasien();
 }

void clear(){
 pasien = new Pasien();
 }

void onSuccess(){
 System.out.println("On success");
 if (getPasien().getId_pasien() == null){
 pasien.setId_pasien(TutorialUtil.getId());
 getListPasien().add(pasien);
 }else{

}

clear();
 }

void onActionFromReset(){
 clear();
 }

void onActionFromEdit(String id_pasien){
 Pasien pas = new Pasien();
 for (Pasien p : getListPasien()){
 if (p.getId_pasien().equals(id_pasien)) { pas = p; }
 }
 System.out.println(pas.toString());
 setPasien(pas);
 }

public List<Pasien> getListPasien() {
 if (listPasien == null)
 listPasien = new ArrayList<Pasien>();
 return listPasien;
 }

public void setListPasien(List<Pasien> listPasien) {
 this.listPasien = listPasien;
 }

public Pasien getPasien() {
 return pasien;
 }

public void setPasien(Pasien pasien) {
 this.pasien = pasien;
 }

public Pasien getPasienrow() {
 if (pasienrow == null) pasienrow = new Pasien();
 return pasienrow;
 }

public void setPasienrow(Pasien pasienrow) {
 this.pasienrow = pasienrow;
 }

}

dan Pasien.java

package com.example.tutorial.entities;

import java.io.Serializable;

import org.apache.tapestry5.beaneditor.NonVisual;

public class Pasien implements Serializable {

/**
 *
 */
 private static final long serialVersionUID = 1L;

@NonVisual
 private String id_pasien;
 private String mr_code;
 private String nama;
 private String alamat;
 private String telpon;
 private String tempat_lahir;
 private java.util.Date tgl_lahir;
 private String kode_pos;
 private int umur;
 private Gender gender;
 private String status_perkawinan;
 private String nama_ayah;
 private String nama_ibu;
 private Gol_Darah gol_darah;
 private Agama agama;
 public String getId_pasien() {
 return id_pasien;
 }
 public void setId_pasien(String id_pasien) {
 this.id_pasien = id_pasien;
 }
 public String getMr_code() {
 return mr_code;
 }
 public void setMr_code(String mr_code) {
 this.mr_code = mr_code;
 }
 public String getNama() {
 return nama;
 }
 public void setNama(String nama) {
 this.nama = nama;
 }
 public String getAlamat() {
 return alamat;
 }
 public void setAlamat(String alamat) {
 this.alamat = alamat;
 }
 public String getTelpon() {
 return telpon;
 }
 public void setTelpon(String telpon) {
 this.telpon = telpon;
 }
 public String getTempat_lahir() {
 return tempat_lahir;
 }
 public void setTempat_lahir(String tempat_lahir) {
 this.tempat_lahir = tempat_lahir;
 }
 public java.util.Date getTgl_lahir() {
 return tgl_lahir;
 }
 public void setTgl_lahir(java.util.Date tgl_lahir) {
 this.tgl_lahir = tgl_lahir;
 }
 public String getKode_pos() {
 return kode_pos;
 }
 public void setKode_pos(String kode_pos) {
 this.kode_pos = kode_pos;
 }
 public int getUmur() {
 return umur;
 }
 public void setUmur(int umur) {
 this.umur = umur;
 }
 public Gender getGender() {
 return gender;
 }
 public void setGender(Gender gender) {
 this.gender = gender;
 }
 public String getStatus_perkawinan() {
 return status_perkawinan;
 }
 public void setStatus_perkawinan(String status_perkawinan) {
 this.status_perkawinan = status_perkawinan;
 }
 public String getNama_ayah() {
 return nama_ayah;
 }
 public void setNama_ayah(String nama_ayah) {
 this.nama_ayah = nama_ayah;
 }
 public String getNama_ibu() {
 return nama_ibu;
 }
 public void setNama_ibu(String nama_ibu) {
 this.nama_ibu = nama_ibu;
 }
 public Gol_Darah getGol_darah() {
 return gol_darah;
 }
 public void setGol_darah(Gol_Darah gol_darah) {
 this.gol_darah = gol_darah;
 }
 public Agama getAgama() {
 return agama;
 }
 public void setAgama(Agama agama) {
 this.agama = agama;
 }

@Override
 public String toString() {
 StringBuffer sb = new StringBuffer();
 sb.append("Id pasien = "+id_pasien);
 sb.append("Nama Pasien =  "+nama);
 return sb.toString();
 }

}

File Gender.java

package com.example.tutorial.entities;

public enum Gender {
 LAKI, PEREMPUAN
 }

File Gol_Darah.java

package com.example.tutorial.entities;

public enum Gol_Darah {
 A,B,O,AB
 }

The result :