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

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