読者です 読者をやめる 読者になる 読者になる

Slim3+GWT のサンプルソース

web.xml


<?xml version="1.0" encoding="utf-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5">
<context-param>
<param-name>slim3.rootPackage</param-name>
<param-value>jp.co.hoshisoft.slime3GWTSample</param-value>
</context-param>



<servlet>
<servlet-name>GWTServiceServlet</servlet-name>
<servlet-class>org.slim3.gwt.server.rpc.GWTServiceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
<servlet-name>GWTServiceServlet</servlet-name>
<url-pattern>*.s3gwt</url-pattern>
</servlet-mapping>




</web-app>

[モジュール]
Main.gwt.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0.3//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.3/distro-source/core/src/gwt-module.dtd">
<module>
<inherits name="com.google.gwt.user.User" />
<inherits name='org.slim3.gwt.emul.S3Emulation' />

<source path="client" />
<source path="shared" />
<entry-point
class="jp.co.hoshisoft.slime3GWTSample.client.MainEntryPoint" />
</module>

[エントリー・ポイント・クラス]
MainEntryPoint.java


package jp.co.hoshisoft.slime3GWTSample.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class MainEntryPoint implements EntryPoint {

public void onModuleLoad() {
RootPanel.get().add(new Main());
}
}

[HTMLファイル]
index.html


<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>星ソフト(Slim3GWTテストプログラム)</title>
<link rel="stylesheet" type="text/css" href="/css/global.css" />
<script type="text/javascript" language="javascript" src="jp.co.hoshisoft.slime3GWTSample.Main/jp.co.hoshisoft.slime3GWTSample.Main.nocache.js"></script>
</head>

<body>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

</body>
</html>

[ユーザーインターフェイス]
Main.java


package jp.co.hoshisoft.slime3GWTSample.client;

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

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class Main extends Composite {

private static MainUiBinder uiBinder = GWT.create(MainUiBinder.class);

interface MainUiBinder extends UiBinder<Widget, Main> {
}

@UiField
Button regist;

@UiField
Button list;

public Main() {
initWidget(uiBinder.createAndBindUi(this));
}

@UiHandler({"regist", "list"})
void handleClick(ClickEvent e) {
if(e.getSource() == regist) {
regist();
}
else if(e.getSource() == list) {
list();
}
}

void regist() {
RootPanel.get().clear();
InputDataBean bean = InputDataBean.getInstance();
bean.setName("");
bean.setEmail("");
List<String> bookArray = new ArrayList<String>();
bean.setBookArray(bookArray);
bean.setGender("M");
bean.setMailsend(true);
bean.setPrefectural("13");
List<String> fruitArray = new ArrayList<String>();
bean.setFruitArray(fruitArray);
bean.setComment("");
Regist reg = new Regist();
RootPanel.get().add(reg);
}

void list() {
RootPanel.get().clear();
MemberList reg = new MemberList();
RootPanel.get().add(reg);
}
}

Main.ui.xml


<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<div id="header">
<h1>星ソフト(Slim3GWTテストプログラム)</h1>
</div>
<div id="menu">
<table>
<tr>
<td><g:Button ui:field="regist">登録</g:Button></td>
</tr>
<tr>
<td><g:Button ui:field="list">登録データ一覧</g:Button></td>
</tr>
</table>
</div>
<div id="body">
<h1>星ソフトのSlim3GWTテストプログラムへようこそ</h1>
</div>
</g:HTMLPanel>
</ui:UiBinder>

Regist.java


package jp.co.hoshisoft.slime3GWTSample.client;

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

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class Regist extends Composite {

private static RegistUiBinder uiBinder = GWT.create(RegistUiBinder.class);
private CheckBox cbBookTbl = null;
private RadioButton
rbGenderTbl = null;
private ListBox fruit = new ListBox(true);

interface RegistUiBinder extends UiBinder<Widget, Regist> {
}

@UiField
TextBox name;

@UiField
TextBox email;

@UiField
VerticalPanel bookPanel;

@UiField
CheckBox mailsend;

@UiField
VerticalPanel genderPanel;

@UiField
ListBox prefectural;

@UiField
VerticalPanel fruitPanel;

@UiField
TextArea comment;

@UiField
Button btnOk;

public Regist() {
initWidget(uiBinder.createAndBindUi(this));
init();
}

public void init() {
InputDataBean bean = InputDataBean.getInstance();

name.setText(bean.getName());
email.setText(bean.getEmail());

cbBookTbl = new CheckBox[ConstValue.contBookArray.length];

List<String> selectBookArray = bean.getBookArray();
for(int i=0;i<ConstValue.contBookArray.length;i++) {
cbBookTbl[i] = new CheckBox(ConstValue.contBookArray[i][0]);
cbBookTbl[i].setName(ConstValue.contBookArray[i][1]);
if(selectBookArray != null) {
if(selectBookArray.contains(ConstValue.contBookArray[i][1])) {
cbBookTbl[i].setValue(true);
}
}
bookPanel.add(cbBookTbl[i]);
}

mailsend.setValue(bean.isMailsend());

rbGenderTbl = new RadioButton[ConstValue.contGenderArray.length];
for(int i=0;i<ConstValue.contGenderArray.length;i++) {
rbGenderTbl[i] = new RadioButton("GENDER", ConstValue.contGenderArray[i][0]);
if(bean.getGender() != null) {
if(bean.getGender().equals(ConstValue.contGenderArray[i][1])) {
rbGenderTbl[i].setValue(true);
}
}
genderPanel.add(rbGenderTbl[i]);
}

for(int i=0;i<ConstValue.contPrefecturalArray.length;i++) {
prefectural.addItem(ConstValue.contPrefecturalArray[i][0], ConstValue.contPrefecturalArray[i][1]);
if(bean.getPrefectural() != null) {
if(bean.getPrefectural().equals(ConstValue.contPrefecturalArray[i][1])) {
prefectural.setSelectedIndex(i);
}
}
}

fruit.setVisibleItemCount(5);
for(int i=0;i<ConstValue.contFruitArray.length;i++) {
fruit.addItem(ConstValue.contFruitArray[i][0], ConstValue.contFruitArray[i][1]);
if(bean.getFruitArray() != null) {
if(bean.getFruitArray().contains(ConstValue.contFruitArray[i][1])) {
fruit.setItemSelected(i, true);
}
}
}
fruitPanel.add(fruit);

comment.setText(bean.getComment());
}

@UiHandler("btnOk")
void handleClick(ClickEvent e) {
InputDataBean bean = InputDataBean.getInstance();

bean.setName(name.getValue());
bean.setEmail(email.getValue());

List<String> selectBook = new ArrayList<String>();
for(int i=0;i<cbBookTbl.length;i++) {
if(cbBookTbl[i].getValue()) {
selectBook.add(cbBookTbl[i].getName());
}
}
bean.setBookArray(selectBook);

bean.setMailsend(mailsend.getValue());

if(rbGenderTbl[0].getValue()) {
bean.setGender("M");
}
if(rbGenderTbl[1].getValue()) {
bean.setGender("W");
}

String selectPrefectural = null;
for(int i=0;i<prefectural.getItemCount();i++) {
if(prefectural.isItemSelected(i)) {
selectPrefectural = prefectural.getValue(i);
break;
}
}
bean.setPrefectural(selectPrefectural);

List<String> selectFruit = new ArrayList<String>();
for(int i=0;i<fruit.getItemCount();i++) {
if(fruit.isItemSelected(i)) {
selectFruit.add(fruit.getValue(i));
}
}
bean.setFruitArray(selectFruit);

bean.setComment(comment.getText());

RootPanel.get().clear();
Confirm reg = new Confirm();
RootPanel.get().add(reg);

}
}

Regist.ui.xml


<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<table>
<tr>
<td>Name</td>
<td><g:TextBox ui:field="name"></g:TextBox></td>
</tr>
<tr>
<td>E-Mail</td>
<td><g:TextBox ui:field="email"></g:TextBox></td>
</tr>
<tr>
<td>購読雑誌</td>
<td>
<g:VerticalPanel ui:field="bookPanel" ></g:VerticalPanel>
</td>
</tr>
<tr>
<td>メルマガ送信有無</td>
<td><g:CheckBox ui:field="mailsend" formValue="mailsend"></g:CheckBox></td>
</tr>
<tr>
<td>性別</td>
<td>
<g:VerticalPanel ui:field="genderPanel" spacing="5"></g:VerticalPanel>
</td>
</tr>
<tr>
<td>都道府県</td>
<td>
<g:ListBox ui:field="prefectural" ></g:ListBox>
</td>
</tr>
<tr>
<td>好きな果物</td>
<td>
<g:VerticalPanel ui:field="fruitPanel" ></g:VerticalPanel>
</td>
</tr>
<tr>
<td>コメント</td>
<td><g:TextArea ui:field="comment"></g:TextArea></td>
</tr>
</table>
<br />
<g:Button ui:field="btnOk">入力完了</g:Button>
</g:HTMLPanel>
</ui:UiBinder>

Confirm.java


package jp.co.hoshisoft.slime3GWTSample.client;

import java.util.Iterator;
import java.util.List;

import jp.co.hoshisoft.slime3GWTSample.client.service.MemberService;
import jp.co.hoshisoft.slime3GWTSample.client.service.MemberServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class Confirm extends Composite {

private static ConfirmUiBinder uiBinder = GWT.create(ConfirmUiBinder.class);

private static MemberServiceAsync service = GWT.create(MemberService.class);

interface ConfirmUiBinder extends UiBinder<Widget, Confirm> {
}

@UiField
Button btnOk;

@UiField
Button btnBack;

@UiField
Grid confirmData;

public Confirm() {
initWidget(uiBinder.createAndBindUi(this));
init();
}

@UiHandler({"btnOk", "btnBack"})
void handleClick(ClickEvent e) {
if(e.getSource() == btnOk) {
regist(InputDataBean.getInstance());
}
else if(e.getSource() == btnBack) {
RootPanel.get().clear();
Regist reg = new Regist();
RootPanel.get().add(reg);
}
}

private void init() {
confirmData.resize(8, 2);
confirmData.setBorderWidth(2);
confirmData.setText(0, 0, "Name");
confirmData.setText(1, 0, "E-Mail");
confirmData.setText(2, 0, "購読雑誌");
confirmData.setText(3, 0, "メルマガ送信有無");
confirmData.setText(4, 0, "性別");
confirmData.setText(5, 0, "都道府県");
confirmData.setText(6, 0, "好きな果物");
confirmData.setText(7, 0, "コメント");

InputDataBean bean = InputDataBean.getInstance();
confirmData.setText(0, 1, bean.getName());
confirmData.setText(1, 1, bean.getEmail());
List<String> bookArray = bean.getBookArray();
if(bookArray == null) {
confirmData.setText(2, 1, "");
}
else {
StringBuilder sb = new StringBuilder();
boolean brSetFlag = false;
Iterator<String> it = bookArray.iterator();
while(it.hasNext()) {
String s = it.next();
for(int i=0;i<ConstValue.contBookArray.length;i++) {
if(ConstValue.contBookArray[i][1].equals(s)) {
if(brSetFlag == true) {
sb.append("<br />");
}
brSetFlag = true;
sb.append(ConstValue.contBookArray[i][0]);
break;
}
}
}
confirmData.setHTML(2, 1, sb.toString());
}
if(bean.isMailsend()) {
confirmData.setText(3, 1, "有");
}
else {
confirmData.setText(3, 1, "無");
}
if("M".equals(bean.getGender())) {
confirmData.setText(4, 1, "男");
}
else {
if("W".equals(bean.getGender())) {
confirmData.setText(4, 1, "女");
}
else {
confirmData.setText(4, 1, "");
}
}
confirmData.setText(5, 1, "");
for(int i=0;i<ConstValue.contPrefecturalArray.length;i++) {
if(ConstValue.contPrefecturalArray[i][1].equals(bean.getPrefectural())) {
confirmData.setText(5, 1, ConstValue.contPrefecturalArray[i][0]);
break;
}
}

List<String> fruitArray = bean.getFruitArray();
if(fruitArray == null) {
confirmData.setText(6, 1, "");
}
else {
StringBuilder sb = new StringBuilder();
boolean brSetFlag = false;
Iterator<String> it = fruitArray.iterator();
while(it.hasNext()) {
String s = it.next();
for(int i=0;i<ConstValue.contFruitArray.length;i++) {
if(ConstValue.contFruitArray[i][1].equals(s)) {
if(brSetFlag == true) {
sb.append("<br />");
}
brSetFlag = true;
sb.append(ConstValue.contFruitArray[i][0]);
break;
}
}
}
confirmData.setHTML(6, 1, sb.toString());
}

confirmData.setHTML(7, 1, htmlEscape(bean.getComment()));

System.out.println("ConstValue.contBookArray.length->" + ConstValue.contBookArray[0].length);
}

private String htmlEscape(String strVar){
StringBuilder strEsc = new StringBuilder();
if(strVar != null) {
for(int i=0;i<strVar.length();i++){
switch(strVar.charAt(i)){
case '<' :
strEsc.append("<");
break;
case '>' :
strEsc.append(">");
break;
case '&' :
strEsc.append("&");
break;
case '\n' :
strEsc.append("<br />");
break;
default :
strEsc.append(strVar.charAt(i));
break;
}
}
}
return strEsc.toString();
}

private void regist(InputDataBean bean) {
service.insert(bean, new AsyncCallback<Void>() {

public void onSuccess(Void result) {
Window.alert("Success!!!");
}

public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
});
}
}

Confirm.ui.xml


<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<g:Grid ui:field="confirmData" ></g:Grid><br />
<g:Button ui:field="btnOk">確認</g:Button>
<g:Button ui:field="btnBack">戻る</g:Button>

</g:HTMLPanel>
</ui:UiBinder>

MemberList.java


package jp.co.hoshisoft.slime3GWTSample.client;

import java.util.List;

import jp.co.hoshisoft.slime3GWTSample.client.service.MemberService;
import jp.co.hoshisoft.slime3GWTSample.client.service.MemberServiceAsync;
import jp.co.hoshisoft.slime3GWTSample.shared.model.Member;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class MemberList extends Composite {

private static MemberListUiBinder uiBinder = GWT.create(MemberListUiBinder.class);

private static MemberServiceAsync service = GWT.create(MemberService.class);

interface MemberListUiBinder extends UiBinder<Widget, MemberList> {
}

@UiField
Button btnDelete;

@UiField
FlexTable tblMember;

public MemberList() {
initWidget(uiBinder.createAndBindUi(this));
init();

}

@UiHandler("btnDelete")
void onClick(ClickEvent e) {

final DialogBox dialogBox = new DialogBox();
dialogBox.setHTML("<br/>全件削除します。よろしんですか?<br /><br />");
dialogBox.setAnimationEnabled(true);
dialogBox.setGlassEnabled(true);
final Button btnOk = new Button("確認");
HorizontalPanel dialogHPanel = new HorizontalPanel();
dialogBox.setWidget(dialogHPanel);
dialogHPanel.setWidth("100%");
dialogHPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
dialogHPanel.add(btnOk);

btnOk.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
service.allDelete(new AsyncCallback<Void>() {
public void onSuccess(Void result) {
dialogBox.hide();
RootPanel.get().clear();
Main reg = new Main();
RootPanel.get().add(reg);
}

public void onFailure(Throwable caught) {

}
});
}
});

final Button btnCancel = new Button("キャンセル");
btnCancel.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
}
});
dialogHPanel.add(btnCancel);
dialogBox.center();
dialogBox.setModal(true);
dialogBox.show();

}

private void init() {
service.allList(new AsyncCallback<List<Member>>() {

public void onSuccess(List<Member> result) {
tblMember.clear();
tblMember.setBorderWidth(2);
tblMember.setHTML(0, 0, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">Name</div>");
tblMember.setHTML(0, 1, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">E-Mail</div>");
tblMember.setHTML(0, 2, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">購読雑誌</div>");
tblMember.setHTML(0, 3, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">メルマガ送信有無</div>");
tblMember.setHTML(0, 4, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">性別</div>");
tblMember.setHTML(0, 5, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">都道府県</div>");
tblMember.setHTML(0, 6, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">好きな果物</div>");
tblMember.setHTML(0, 7, "<div align=\"center\" style=\"background-color:silver;font-weight:bold\">コメント</div>");

for (int i = 0; i < result.size(); i++) {
tblMember.setText(i+1, 0, result.get(i).getName());
tblMember.setText(i+1, 1, result.get(i).getEmail());
tblMember.setHTML(i+1, 2, convertCode2HTML(result.get(i).getBookArray(), ConstValue.contBookArray));
if("1".equals(result.get(i).getMailsend())) {
tblMember.setText(i+1, 3, "有");
}
else {
if("1".equals(result.get(i).getMailsend())) {
tblMember.setText(i+1, 3, "無");
}
else {
tblMember.setText(i+1, 3, "");
}
}
if("M".equals(result.get(i).getGender())) {
tblMember.setText(i+1, 4, "男");
}
else {
if("W".equals(result.get(i).getGender())) {
tblMember.setText(i+1, 4, "女");
}
else {
tblMember.setText(i+1, 4, "");
}
}
tblMember.setHTML(i+1, 5, convertCode2HTML(result.get(i).getPrefectural(), ConstValue.contPrefecturalArray));
tblMember.setHTML(i+1, 6, convertCode2HTML(result.get(i).getFruitArray(), ConstValue.contFruitArray));
tblMember.setHTML(i+1, 7, htmlEscape(result.get(i).getComment()));
}
}

public void onFailure(Throwable caught) {
Window.alert(caught.getMessage());
}
});
}

private String convertCode2HTML(String code, String contCodeArray) {
StringBuilder sb = new StringBuilder();
boolean brSetFlag = false;

if(code != null) {
String codeTbl = code.split(";");
for(int i=0;i<codeTbl.length;i++) {
for(int j=0;j<contCodeArray.length;j++) {
if(contCodeArray[j][1].equals(codeTbl[i])) {
if(brSetFlag == true) {
sb.append("<br />");
}
brSetFlag = true;
sb.append(contCodeArray[j][0]);
break;
}
}
}
}
return sb.toString();
}

private String htmlEscape(String strVar){
StringBuilder strEsc = new StringBuilder();
if(strVar != null) {
for(int i=0;i<strVar.length();i++){
switch(strVar.charAt(i)){
case '<' :
strEsc.append("<");
break;
case '>' :
strEsc.append(">");
break;
case '&' :
strEsc.append("&");
break;
case '\n' :
strEsc.append("<br />");
break;
default :
strEsc.append(strVar.charAt(i));
break;
}
}
}
return strEsc.toString();
}
}

MemberList.ui.xml


<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">
<ui:style>
.important {
font-weight: bold;
}
</ui:style>
<g:HTMLPanel>
<g:FlexTable ui:field="tblMember"></g:FlexTable>
<br />
<g:Button ui:field="btnDelete">全件削除</g:Button>
</g:HTMLPanel>
</ui:UiBinder>

[共通クラス]
ConstValue.java


package jp.co.hoshisoft.slime3GWTSample.client;

public class ConstValue {
public static String contBookArray = {{"WEB-DB Press","WEB-DB_Press"},
{"JAVA Press","JAVA_Press"},
{"Java World","Java_World"},
{"DosV Magazine","DosV_Magazine"}};

public static String contGenderArray = {{"男","M"},{"女","W"}};

public static String contPrefecturalArray = {{"北海道","01"},
{"青森県","02"},
{"岩手県","03"},
{"宮城県","04"},
{"秋田県","05"},
{"東京都","13"},
{"沖縄県","47"}};



public static String
[] contFruitArray = {{"りんご","01"},
{"みかん","02"},
{"柿","03"},
{"バナナ","04"},
{"メロン","05"},
{"イチゴ","06"}};
}

InputDataBean.java


package jp.co.hoshisoft.slime3GWTSample.client;

import java.io.Serializable;
import java.util.List;

public class InputDataBean implements Serializable {

private static final long serialVersionUID = 1L;

private static InputDataBean instance = new InputDataBean();

private String name=null;
private String email=null;
private List<String> bookArray = null;
private boolean mailsend = false;
private String gender = null;
private String prefectural = null;
private List<String> fruitArray = null;
private String comment = null;

private InputDataBean() {
}

public static InputDataBean getInstance() {
return instance;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public List<String> getBookArray() {
return bookArray;
}

public void setBookArray(List<String> bookArray) {
this.bookArray = bookArray;
}

public boolean isMailsend() {
return mailsend;
}

public void setMailsend(boolean mailsend) {
this.mailsend = mailsend;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getPrefectural() {
return prefectural;
}

public void setPrefectural(String prefectural) {
this.prefectural = prefectural;
}

public List<String> getFruitArray() {
return fruitArray;
}

public void setFruitArray(List<String> fruitArray) {
this.fruitArray = fruitArray;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}
}

[サービスクラス]
MemberService.java


package jp.co.hoshisoft.slime3GWTSample.client.service;

import java.util.List;

import jp.co.hoshisoft.slime3GWTSample.client.InputDataBean;
import jp.co.hoshisoft.slime3GWTSample.shared.model.Member;

import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("service.s3gwt")
public interface MemberService extends RemoteService {

void insert(InputDataBean bean);
List<Member> allList();
void allDelete();

}

MemberServiceAsync.java


package jp.co.hoshisoft.slime3GWTSample.client.service;

import java.util.List;

import jp.co.hoshisoft.slime3GWTSample.client.InputDataBean;
import jp.co.hoshisoft.slime3GWTSample.shared.model.Member;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface MemberServiceAsync {

void insert(InputDataBean bean, AsyncCallback<Void> callback);

void allList(AsyncCallback<List<Member>> callback);

void allDelete(AsyncCallback<Void> callback);

}

MemberServiceImpl.java


package jp.co.hoshisoft.slime3GWTSample.server.service;

import java.util.Iterator;
import java.util.List;

import org.slim3.datastore.Datastore;

import com.google.appengine.api.datastore.Transaction;

import jp.co.hoshisoft.slime3GWTSample.client.InputDataBean;
import jp.co.hoshisoft.slime3GWTSample.client.service.MemberService;
import jp.co.hoshisoft.slime3GWTSample.server.meta.MemberMeta;
import jp.co.hoshisoft.slime3GWTSample.shared.model.Member;

public class MemberServiceImpl implements MemberService {

public void insert(InputDataBean bean) {
Member member = new Member();

member.setName(bean.getName());
member.setEmail(bean.getEmail());
member.setBookArray(bindCode(bean.getBookArray()));
member.setMailsend(bean.isMailsend() ? "1" : "0");
member.setGender(bean.getGender());
member.setPrefectural(bean.getPrefectural());
member.setFruitArray(bindCode(bean.getFruitArray()));
member.setComment(bean.getComment());

Transaction tx = Datastore.beginTransaction();
Datastore.put(member);
Datastore.commit(tx);

}

public List<Member> allList() {

MemberMeta e = new MemberMeta();
List<Member> list = Datastore.query(e)
.sort(e.name.asc)
.asList();

return list;
}

public void allDelete() {
MemberMeta e = new MemberMeta();
Datastore.delete(Datastore.query(e).asKeyList());
}

private String bindCode(List<String> codeList) {
if(codeList == null) {
return "";
}
StringBuilder sb = new StringBuilder();
boolean brSetFlag = false;
Iterator<String> it = codeList.iterator();
while(it.hasNext()) {
String s = it.next();
if(brSetFlag == true) {
sb.append(";");
}
brSetFlag = true;
sb.append(s);
}
return sb.toString();
}
}

[モデルクラス]
Member.java


package jp.co.hoshisoft.slime3GWTSample.shared.model;

import java.io.Serializable;
import java.util.Date;

import com.google.appengine.api.datastore.Key;

import org.slim3.datastore.Attribute;
import org.slim3.datastore.Model;

@Model(schemaVersion = 1)
public class Member implements Serializable {

private static final long serialVersionUID = 1L;

@Attribute(primaryKey = true)
private Key key;

@Attribute(version = true)
private Long version;

private String name;
private String email;
private String bookArray;
private String mailsend;
private String gender;
private String prefectural;
private String fruitArray;
private String comment;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getBookArray() {
return bookArray;
}

public void setBookArray(String bookArray) {
this.bookArray = bookArray;
}

public String getMailsend() {
return mailsend;
}

public void setMailsend(String mailsend) {
this.mailsend = mailsend;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getPrefectural() {
return prefectural;
}

public void setPrefectural(String prefectural) {
this.prefectural = prefectural;
}

public String getFruitArray() {
return fruitArray;
}

public void setFruitArray(String fruitArray) {
this.fruitArray = fruitArray;
}

public String getComment() {
return comment;
}

public void setComment(String comment) {
this.comment = comment;
}

public Date getCreatedDate() {
return createdDate;
}

public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}

private Date createdDate = new Date();


public Key getKey() {
return key;
}

public void setKey(Key key) {
this.key = key;
}

public Long getVersion() {
return version;
}

public void setVersion(Long version) {
this.version = version;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + *1;
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Member other = (Member) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
return true;
}
}

MemberMeta.java


package jp.co.hoshisoft.slime3GWTSample.server.meta;

//@javax.annotation.Generated(value = { "slim3-gen", "@VERSION@" }, date = "2010-06-28 00:05:51")
public final class MemberMeta extends org.slim3.datastore.ModelMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> {

public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> bookArray = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "bookArray", "bookArray");
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> comment = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "comment", "comment");
public final org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, java.util.Date> createdDate = new org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, java.util.Date>(this, "createdDate", "createdDate", java.util.Date.class);
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> email = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "email", "email");
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> fruitArray = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "fruitArray", "fruitArray");
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> gender = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "gender", "gender");
public final org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, com.google.appengine.api.datastore.Key> key = new org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, com.google.appengine.api.datastore.Key>(this, "__key__", "key", com.google.appengine.api.datastore.Key.class);
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> mailsend = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "mailsend", "mailsend");
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> name = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "name", "name");
public final org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member> prefectural = new org.slim3.datastore.StringAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member>(this, "prefectural", "prefectural");
public final org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, java.lang.Long> version = new org.slim3.datastore.CoreAttributeMeta<jp.co.hoshisoft.slime3GWTSample.shared.model.Member, java.lang.Long>(this, "version", "version", java.lang.Long.class);
private static final MemberMeta slim3_singleton = new MemberMeta();

public static MemberMeta get() {
return slim3_singleton;
}

public MemberMeta() {
super("Member", jp.co.hoshisoft.slime3GWTSample.shared.model.Member.class);
}

@Override
public jp.co.hoshisoft.slime3GWTSample.shared.model.Member entityToModel(com.google.appengine.api.datastore.Entity entity) {
jp.co.hoshisoft.slime3GWTSample.shared.model.Member model = new jp.co.hoshisoft.slime3GWTSample.shared.model.Member();
model.setBookArray*2;
model.setComment*3;
model.setCreatedDate*4;
model.setEmail*5;
model.setFruitArray*6;
model.setGender*7;
model.setKey(entity.getKey());
model.setMailsend*8;
model.setName*9;
model.setPrefectural*10;
model.setVersion*11;
return model;
}

@Override
public com.google.appengine.api.datastore.Entity modelToEntity(java.lang.Object model) {
jp.co.hoshisoft.slime3GWTSample.shared.model.Member m = (jp.co.hoshisoft.slime3GWTSample.shared.model.Member) model;
com.google.appengine.api.datastore.Entity entity = null;
if (m.getKey() != null) {
entity = new com.google.appengine.api.datastore.Entity(m.getKey());
} else {
entity = new com.google.appengine.api.datastore.Entity(kind);
}
entity.setProperty("bookArray", m.getBookArray());
entity.setProperty("comment", m.getComment());
entity.setProperty("createdDate", m.getCreatedDate());
entity.setProperty("email", m.getEmail());
entity.setProperty("fruitArray", m.getFruitArray());
entity.setProperty("gender", m.getGender());
entity.setProperty("mailsend", m.getMailsend());
entity.setProperty("name", m.getName());
entity.setProperty("prefectural", m.getPrefectural());
entity.setProperty("version", m.getVersion());
entity.setProperty("slim3.schemaVersion", 1);
return entity;
}

@Override
protected com.google.appengine.api.datastore.Key getKey(Object model) {
jp.co.hoshisoft.slime3GWTSample.shared.model.Member m = (jp.co.hoshisoft.slime3GWTSample.shared.model.Member) model;
return m.getKey();
}

@Override
protected void setKey(Object model, com.google.appengine.api.datastore.Key key) {
validateKey(key);
jp.co.hoshisoft.slime3GWTSample.shared.model.Member m = (jp.co.hoshisoft.slime3GWTSample.shared.model.Member) model;
m.setKey(key);
}

@Override
protected long getVersion(Object model) {
jp.co.hoshisoft.slime3GWTSample.shared.model.Member m = (jp.co.hoshisoft.slime3GWTSample.shared.model.Member) model;
return m.getVersion() != null ? m.getVersion().longValue() : 0L;
}

@Override
protected void incrementVersion(Object model) {
jp.co.hoshisoft.slime3GWTSample.shared.model.Member m = (jp.co.hoshisoft.slime3GWTSample.shared.model.Member) model;
long version = m.getVersion() != null ? m.getVersion().longValue() : 0L;
m.setVersion(Long.valueOf(version + 1L));
}

@Override
public String getSchemaVersionName() {
return "slim3.schemaVersion";
}

@Override
public String getClassHierarchyListName() {
return "slim3.classHierarchyList";
}

}

[CSSファイル]
global.css


@CHARSET "utf-8";

body { background-color: #EEEEEE; }



.gwt-DialogBox {
background-color: silver;
border-color: gray;
border-style: solid;
border-width: 5px;
}

.gwt-DialogBox.Caption {
background-color: blue;
}

*1:key == null) ? 0 : key.hashCode(

*2:java.lang.String) entity.getProperty("bookArray"

*3:java.lang.String) entity.getProperty("comment"

*4:java.util.Date) entity.getProperty("createdDate"

*5:java.lang.String) entity.getProperty("email"

*6:java.lang.String) entity.getProperty("fruitArray"

*7:java.lang.String) entity.getProperty("gender"

*8:java.lang.String) entity.getProperty("mailsend"

*9:java.lang.String) entity.getProperty("name"

*10:java.lang.String) entity.getProperty("prefectural"

*11:java.lang.Long) entity.getProperty("version"