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 :

Published by

saifiahmada

Begin a big Process with a bit trying

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