membuat layout sebagai komponen template tapestry5

File-file yang akan dibuat :

Cetakan.tml, Cetakan.java, cetakan.css

monggo cak 😀

Cetakan.tml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
 xmlns:p="tapestry:parameter">
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
 <title>${title}</title>
 </head>
 <body>
 <div id="header">
 <center><h3>Belajar Tapestry 5</h3></center>
 </div>
 <div id="page">

<div id="kiri">
 <ul><t:pagelink page="master/mahasiswa">Master Mahasiswa</t:pagelink></ul>
 <ul><t:pagelink page="master/pasien">Master Pasien</t:pagelink></ul>
 </div>
 <div id="content"><fieldset><t:body/></fieldset></div>

</div>
 </body>
 </html>

File Cetakan.java

package com.example.tutorial.components;

import org.apache.tapestry5.BindingConstants;
 import org.apache.tapestry5.annotations.IncludeStylesheet;
 import org.apache.tapestry5.annotations.Parameter;
 import org.apache.tapestry5.annotations.Property;

@IncludeStylesheet("context:layout/cetakan.css")
 public class Cetakan {

@SuppressWarnings("unused")
 @Property
 @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
 private String title;

}

File cetakan.css

body {

margin: 0;
 padding: 0;
 background: #FFFFFF url( images/img21.jpg ) repeat-x;
 text-align: justify;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 color: #626262;
 }
 input {
 padding: 2px;
 /*background: #FEFEFE url( images/img13.gif ) repeat-x;
 */
 border: 1px solid #b3d515;
 font: normal 1em Arial, Helvetica, sans-serif;
 }

select{
 border:1px;
 border-style:solid;
 border-color:#b3d515;
 }

textarea{
 border: 1px solid #b3d515;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 }

.button {
 border: 1px solid #000000;
 padding: 2px 2px 2px 2px;
 margin-left : 2px;
 margin-right: 2px;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 background: #b3d515 url( images/backbutton.jpg ) repeat-x;
 }

fieldset {
 color: #000000;
 border: 1px solid #b3d515;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 }

h3 {
 color : #ffffff;
 }

table {
 cellspacing : 0;
 cellpadding : 0;
 font-family: Arial, Helvetica, sans-serif;
 font-size: 12px;
 }

#header {
 height : 50px;
 }

#page{
 width : 1250px;
 }

#kiri {
 width : 200px;
 float : left;
 margin : 0px 0px 0px 0px;
 padding: 0px 0px 0px 0px;

}

.menu {
 display : block;
 background : #b3d515;
 height : 23px;
 width : 200px;
 }

#content {
 margin-left : 0px;
 padding-left : 5px;
 width : 1000px;
 float : left;
 }

#kanan {
 width : 150px;
 float:left;
 }

.sidebar ul {

margin: 1px 0px 1px 4px;
 padding: 0px 0px 0px 0px;

}

.sidebar a {
 display: block;
 height : 25px;
 width : 180px;
 color : #000000;
 text-decoration: none;
 font-weight: bold;
 background: #b3d515;
 /*padding : 5px 0px 0px 10px;*/
 padding : 5px 0px 0px 10px;
 }

.sidebar a:hover {
 color : #ffffff;
 font-weight: bold;
 text-decoration: none;
 background: #ffcc00;
 }

/*data grid customize*/

DIV.t-data-grid {
 font-family: Arial, Helvetica, sans-serif;
 margin-top:20px;
 margin-bottom:20px;
 }

DIV.t-data-grid-pager {
 margin: 8px 0px;
 }

DIV.t-data-grid-pager A, DIV.t-data-grid-pager SPAN.current {
 text-decoration: none;
 color: black;
 padding: 2px 5px;
 font-size: 11px;
 border: 1px solid #b3d515;
 margin-right: 5px;
 }

DIV.t-data-grid-pager A:hover {
 border: 1px solid black;
 }

DIV.t-data-grid-pager SPAN.current {
 color: white;
 border: 1px solid #000066;
 background-color: #b3d515;
 }

TABLE.t-data-grid {
 border-collapse: collapse;
 border-left: 1px solid #000066;
 border-top: 1px solid #000066;
 background-color: #000066;
 font-size: 12px;
 }

table.t-data-grid thead {
 border-top: 1px solid #b3d515; /* For Firefox */
 }

TABLE.t-data-grid THEAD TR {
 color: white;
 background-color: #ffffff;
 }

TABLE.t-data-grid THEAD TR TH {
 text-align: left;
 padding: 1px 3px;
 white-space: nowrap;
 border-left: 1px solid #b3d515;
 border-right: 1px solid #b3d515;
 border-bottom: 1px solid #b3d515;
 background-color:#b3d515;
 /*width: 150px;*/
 }

TABLE.t-data-grid TBODY TR {
 background-color: #ffffff;
 }

TABLE.t-data-grid TBODY TR.odd {
 background-color: #eefbb1;
 }

TABLE.t-data-grid TBODY TR.even {
 background-color: #ffffff;
 }

TABLE.t-data-grid TBODY TR TH A {
 color: white;
 }

TABLE.t-data-grid TBODY TR TD {
 border-right: 1px solid #b3d515;
 border-left: 1px solid #b3d515;
 border-bottom: 1px solid #b3d515;
 padding: 1px 3px;
 }

untuk menggunakan komponen layout ini :

buat file MasterPegawai.tml

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

<fieldset><legend>Master Pegawai</legend>
 <t:beaneditform t:id="pegawai" object="pegawai"/>
 </fieldset>

</html>

dan file MasterPegawai.java

package com.example.tutorial.pages.master;

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

import com.example.tutorial.entities.Pegawai;

public class MasterPegawai {

@Property
 private Pegawai pegawai;

@SetupRender
 void setupRender(){
 if (pegawai == null) pegawai = new Pegawai();
 }

}

dan HASILNYA adalah “bim salabimmmm”

File tambahan (Pegawai.java)

package com.example.tutorial.entities;

import java.io.Serializable;

public class Pegawai implements Serializable {

private String id_pegawai;

private String nama_pegawai;

private String alamat;

private String nip;

private java.util.Date tgl_lahir;

private String tempat_lahir;

private Golongan golongan;

public String getId_pegawai() {
 return id_pegawai;
 }

public void setId_pegawai(String id_pegawai) {
 this.id_pegawai = id_pegawai;
 }

public String getNama_pegawai() {
 return nama_pegawai;
 }

public void setNama_pegawai(String nama_pegawai) {
 this.nama_pegawai = nama_pegawai;
 }

public String getAlamat() {
 return alamat;
 }

public void setAlamat(String alamat) {
 this.alamat = alamat;
 }

public String getNip() {
 return nip;
 }

public void setNip(String nip) {
 this.nip = nip;
 }

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 getTempat_lahir() {
 return tempat_lahir;
 }

public void setTempat_lahir(String tempat_lahir) {
 this.tempat_lahir = tempat_lahir;
 }

public Golongan getGolongan() {
 return golongan;
 }

public void setGolongan(Golongan golongan) {
 this.golongan = golongan;
 }

@Override
 public String toString() {
 StringBuffer sb = new StringBuffer();
 sb.append("ID Pegawai : "+id_pegawai);
 sb.append("Nama Pegawai : "+nama_pegawai);
 sb.append("Alamat : "+alamat);
 return sb.toString();
 }

}

File Golongan.java

package com.example.tutorial.entities;

public enum Golongan {
 I, II, IIIA, IIIB, IIIC, IVA, IVB, IVC, IVD
 }
Advertisements

membuat project tapestry 5 menggunakan maven

Buka konsole -> masuk ke directory workspace Eclipse ->

mvn -DarchetypeVersion=5.2.5 -Darchetype.interactive=false -DgroupId=com.example -DarchetypeArtifactId=quickstart -Dversion=1.0-SNAPSHOT -DarchetypeGroupId=org.apache.tapestry -Dpackage=com.example.xnuxerx -DartifactId=xnuxerx --batch-mode -DarchetypeRepository=http://tapestry.apache.org archetype:generate

jika sukses :

kemudian ketikkan command  mvn eclipse:eclipse

setelah sukses seperti gambar di atas. project sudah bisa di export lewat IDE Eclipse , dalam Eclipse pilih menu File->Import->General->Existing Projects into Workspace.

monitoring stok aplikasi perpusq tapestry5

File .tml

<html t:type="layout2" title="Monitoring Stok"
 xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
 xmlns:p="tapestry:parameter">

<script>
 function pop(){
 window.open("PopupPageLink.tml","Window1","menubar=no,width=430,height=360,toolbar=no");
 }
 </script>

<form t:type="form" t:id="form">
 <fieldset><legend>Monitoring Stok</legend>

<table>
 <tr>
 <td>Kode Buku</td>
 <td>:</td>
 <td><input t:type="TextField" t:id="kode"/></td>
 </tr>

<tr>
 <td>Judul Buku</td>
 <td>:</td>
 <td><input t:type="TextField" t:id="judul"/></td>
 </tr>

<tr>
 <td></td>
 <td></td>
 <td><br/><input t:type="Submit" t:id="filter" t:value="Filter"/>
 <input t:type="Submit" t:id="reset" t:value="Reset"/></td>
 </tr>
 </table>

</fieldset>
 <table t:type="grid" t:source="listMapStok" t:row="mapstok" t:rowsPerPage="20" rowClass="${evenodd}">
 <t:parameter name="kode_bukucell">
 <a t:type="actionlink" t:id="gotoBuku" t:context="${mapstok.id_buku}">${mapstok.kode_buku}</a>
 </t:parameter>

<t:parameter name="keluarcell">
 <!--<t:actionlink t:id="gotoPopupNis" style="background-image: none" t:context="${mapstok.id_buku}"
 onclick="window.open('DetailMonStok.tml','window','width=640,height=470');">
 ${mapstok.keluar}
 </t:actionlink>-->
 <t:if test="mapstokkeluar">
 <t:actionlink t:id="gotoPopupNis" t:context="${mapstok.id_buku}">
 ${mapstok.keluar}
 </t:actionlink>
 <p:else>
 0
 </p:else>
 </t:if>
 </t:parameter>
 </table>
 </form>

</html>

File .java

klik code

menjajal komponen select tapestry5

File .tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<t:form>
 <t:label for="hp"/><t:select t:id="hp" t:model="literal:nokia,cross,sony,motorola"/>
 <t:submit t:value="Pesan"/>
 </t:form>
 <t:if test="hp">
 Item dipesan : ${hp}
 </t:if>

</html>

File .java

package com.example.tutorial.pages;

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

public class Tselect {

@Property
 @Persist
 private String hp;

void onActivate(String hp){
 hp = hp;
 }

Object onPassivate(){
 return hp;
 }

}

menjajal komponen loop tapestry5

File .tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<table>
 <thead bgcolor="#cccccc">
 <tr>
 <th>Id Barang</th>
 <th>Nama Barang</th>
 <th>Harga Barang</th>
 </tr>
 </thead>
 <tbody>
 <tr t:type="Loop" t:source="barangs" t:value="barang" bgcolor="#ffcc00">
 <td>${barang.id_barang}</td>
 <td>${barang.nama_barang}</td>
 <td>${barang.harga_barang}</td>
 </tr>
 </tbody>
 </table>

</html>

File .java

package com.example.tutorial.pages;

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

import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.annotations.SetupRender;
 import com.example.tutorial.entities.Barang;

public class Tloop {

private List<Barang> barangs;

@Property
 private Barang barang;

@SetupRender
 void setupRender(){
 barang = new Barang();
 }

public List<Barang> getBarangs(){
 barangs = new ArrayList<Barang>();
 barangs.add(new Barang("01", "Barang A", "5000"));
 barangs.add(new Barang("02", "Barang B", "4000"));
 barangs.add(new Barang("03", "Barang C", "6000"));
 return barangs;
 }
 }

menambahkan checkbox pada grid tapestry5

File .tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<t:zone t:id="zone">
 <t:if test="brg">
 <t:beandisplay object="brg"/>
 </t:if>
 </t:zone>

<t:form t:id="form">
 <t:grid t:source="listbarang" t:row="barang" t:add="check" t:reorder="check">
 <t:parameter name="nama_barangcell">
 <t:actionlink t:id="gotodetail" t:context="${barang.id_barang}" t:zone="zone">${barang.nama_barang}</t:actionlink>
 </t:parameter>

<t:parameter name="checkcell">
 <t:checkbox t:id="check" t:value="check"/>
 </t:parameter>
 </t:grid>

</t:form>

</html>

File .java

package com.example.tutorial.pages;

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

import org.apache.tapestry5.annotations.InjectComponent;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.annotations.SetupRender;
 import org.apache.tapestry5.corelib.components.Zone;

import com.example.tutorial.entities.Barang;

public class VariasiKomponen {

private List<Barang> listBarang;

private Barang brg;

@InjectComponent
 private Zone zone;

@Property
 private Barang barang;

private boolean check;

@SetupRender
 void setupRender(){
 if (barang == null)
 barang = new Barang();

}

public List<Barang> getListBarang(){
 listBarang = new ArrayList<Barang>();
 listBarang.add(new Barang("1", "Lifebouyz", "Rp 2300"));
 listBarang.add(new Barang("2", "Shinzuis", "Rp 3500"));
 listBarang.add(new Barang("3", "Pepcodent", "Rp 3500"));
 listBarang.add(new Barang("4", "Clearz", "Rp 7500"));
 return listBarang;
 }

Object onActionFromGotoDetail(String id_barang){
 int i = Integer.parseInt(id_barang) - 1;
 Barang b = getListBarang().get(i);
 setBrg(b);
 return zone.getBody();
 }

public Barang getBrg() {
 return brg;
 }

public void setBrg(Barang brg) {
 this.brg = brg;
 }

public boolean isCheck() {
 return check;
 }

public void setCheck(boolean check) {
 this.check = check;
 }

}

mencoba komponen radiogroup tapestry5

File .tml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">

<t:form t:id="form">
 Barang yang dipesan
 <t:label for="rokok"/>:<br/>
 <t:radiogroup t:id="rokok">
 <t:radio t:id="gudang"/><t:label for="gudang"/>
 <t:radio t:id="dyarum"/><t:label for="dyarum"/>
 <t:radio t:id="djizamzoe"/><t:label for="djizamzoe"/>
 </t:radiogroup><br/>

<t:label for="shampoo"/>:<br/>
 <t:radiogroup t:id="shampoo">
 <t:radio t:id="clear"/><t:label for="clear"/>
 <t:radio t:id="pantene"/><t:label for="pantene"/>
 <t:radio t:id="sunsilk"/><t:label for="sunsilk"/>
 </t:radiogroup><br/><br/>

<t:submit t:id="submit" t:value="Pesan"/>
 </t:form>

<t:if test="item">
 ${item}
 </t:if>

</html>

File .java

package com.example.tutorial.pages;

import org.apache.tapestry5.annotations.Persist;

import com.example.tutorial.entities.Rokok;

public class Tradiogroup {

@Persist
 private String item;

private Rokok rokok;

private String shampoo;

Object onSelectedFromSubmit(){
 String items = "Shampoo : " + getShampoo() +", Rokok : "+getRokok();
 setItem(items);
 return this;
 }

public String getClear(){return "Clear"; }

public String getPantene() { return "Pantene"; }

public String getSunsilk() { return "Sunsilk"; }

public Rokok getGudang(){
 return rokok.GUDANG;
 }

public Rokok getDyarum(){
 return rokok.DYARUM;
 }

public Rokok getDjizamzoe(){
 return rokok.DJIZAMZOE;
 }

public Rokok getRokok() {
 return rokok;
 }

public void setRokok(Rokok rokok) {
 this.rokok = rokok;
 }

public String getShampoo() {
 return shampoo;
 }

public void setShampoo(String shampoo) {
 this.shampoo = shampoo;
 }

public String getItem() {
 return item;
 }

public void setItem(String item) {
 this.item = item;
 }

}

File Rokok.java

 package com.example.tutorial.entities;

public enum Rokok {
 GUDANG, DYARUM, DJIZAMZOE
 }