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; = 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"

<fieldset><legend>Master Kecamatan</legend>

<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: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"/>

<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 name="nama_kecamatancell">
<t:actionlink t:id="edit" context="kecamatanrow.id_kecamatan">${kecamatanrow.nama_kecamatan}</t:actionlink>
<t:parameter name="id_kabupatencell">


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 {

private Kecamatan kecamatan;

private Kecamatan kecamatanrow;

private List<Kecamatan> listKecamatan;

private boolean del;

private List<Kecamatan> listDelete;

private ModelFactory modelKabupaten;

void onSelectedFromSave(){
if (getKecamatan().getId_kecamatan() == null){

void onSelectedFromReset(){

void onSelectedFromSearch(){


void onSelectedFromDelete(){


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

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

private int i = 0;
public String getevenOdd(){
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){

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 😀


Published by


Begin a big Process with a bit trying

Leave a Reply

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

You are commenting using your 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