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

先日作成したサンプルに修正、追加しました。

先日作成したサンプルに修正、追加しました。


menu.jsp


<%@page pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://www.slim3.org/functions"%>

<div id="menu">
<ul>
<li><a href="${f:h('/regist/index')}">入力>確認>登録のテスト</a></li>
<li><a href="${f:h('/regist/list')}">登録データ一覧</a></li>
</ul>
</div>




ListController.java ・・・・登録済みデータの一覧表示

package slim3Sample1.controller.regist;

import java.util.List;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.util.RequestMap;

import slim3Sample1.model.Member;
import slim3Sample1.service.MemberService;

public class ListController extends Controller {

MemberService service = new MemberService();

@Override
public Navigation run() {
RequestMap requestMap = new RequestMap(request);
List list = service.allList();
requestMap.put("AllList", list);
return forward("list.jsp");
}
}



DeleteController.java ・・・・登録済みデータを全て削除


package slim3Sample1.controller.regist;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import slim3Sample1.service.MemberService;

public class DeleteController extends Controller {

MemberService service = new MemberService();

@Override
public Navigation run() {
service.allDelete();
return forward("delete.jsp");
}
}



MemberService.java ・・・ allList, allDeleteメソッドを追加


package slim3Sample1.service;

import java.util.List;
import java.util.Map;
import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;
import com.google.appengine.api.datastore.Transaction;

import slim3Sample1.meta.MemberMeta;
import slim3Sample1.model.Member;

public class MemberService {
public Member member(Map input) {
Member member = new Member();
BeanUtil.copy(input, member);
Transaction tx = Datastore.beginTransaction();
Datastore.put(member);
Datastore.commit(tx);
return member;
}

public List allList() {

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

return list;
}

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



list.jsp ・・・・登録済みデータを一覧表示画面


<%@page pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="f" uri="http://www.slim3.org/functions"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>regist List</title>
<link rel="stylesheet" type="text/css" href="/css/global.css" />
</head>
<body>

<form action="${f:url('delete')}" method="post">
<table border=1 >
<caption>【一覧表】</caption>
<thead bgcolor="#cccccc">
<tr>
<th>Key</th><th>Version</th>
<th>Name</th><th>E-Mail</th><th>購読雑誌</th>
<th>メルマガ送信有無</th><th>性別</th><th>都道府県</th>
<th>好きな果物</th><th>コメント</th>
</tr>
</thead>
<tbody>
<c:forEach items="${AllList}" var="member">
<tr>
<td><c:out value="${member.key}"/></td>
<td><c:out value="${member.version}"/></td>
<td><c:out value="${member.name}"/></td>
<td><c:out value="${member.email}"/></td>
<td>
<c:forTokens items="${member.bookArray}" delims=";" var="book" >
<c:out value="${book}"/><br />
</c:forTokens>
</td>
<td>
<c:choose>
<c:when test="${member.mailsend == 'on'}">メルマガ送信有</c:when>
<c:when test="${member.mailsend != 'on'}">メルマガ送信無</c:when>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${member.gender == 'M'}">男</c:when>
<c:when test="${member.gender == 'W'}">女</c:when>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${member.prefectural == '1'}">北海道</c:when>
<c:when test="${member.prefectural == '2'}">青森</c:when>
<c:when test="${member.prefectural == '13'}">東京</c:when>
</c:choose>
</td>
<td>
<c:forTokens items="${member.fruitArray}" delims=";" var="value" >
<c:if test="${value == '1'}">りんご<br /></c:if>
<c:if test="${value == '2'}">柿<br /></c:if>
<c:if test="${value == '3'}">みかん<br /></c:if>
</c:forTokens>
</td>

<td>${f:br(member.comment)}</td>
</tr>
</c:forEach>
</tbody>
</table>
<br />
<input type="submit" value="全件削除"/>
</form>
</body>
</html>



delete.jsp ・・・・削除完了画面


<%@page pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="f" uri="http://www.slim3.org/functions"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>regist Delete</title>
<link rel="stylesheet" type="text/css" href="/css/global.css" />
</head>
<body>
<p>削除が完了しました。</p>
</body>
</html>