Top > SAStrutsあれこれ > 「データベースを使ったサンプル」を軽く改造(7)

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 
 
-
|
|
|
|
|
-
|
|
|
!
|
!
 
 
 
-
|
|
!
 
 
 
-
|
|
!
 
 
 
-
|
|
-
|
-
|
|
!
!
|
|
|
!
    //一括更新画面表示用
    @Execute(validator = false)
    public String edit_for_bulk_upd() {
        deptItems = departmentService.findAll();
        empItems = employeeService.findAll();
 
        //エンティティ→アクションフォームにコピーします。
        employeeForm.empUpdateItems = new ArrayList<EmployeeForm>();
        for( Employee e : empItems ) {
            EmployeeForm f = Beans.createAndCopy(EmployeeForm.class, e).execute();
            f.update_check = false;
            employeeForm.empUpdateItems.add(f);
        }
        return "edit_for_bulk_upd.jsp";
    }
    
    //一括更新内容確認画面表示用
    @Execute(validator = false)
    public String confirm_for_bulk_upd() {
        deptItems = departmentService.findAll();
        return "confirm_for_bulk_upd.jsp";
    }
    
    //一括更新内容確認画面→一括更新画面への戻る
    @Execute(validator = false)
    public String back_to_edit_for_bulk_upd() {
        deptItems = departmentService.findAll();
        return "edit_for_bulk_upd.jsp";
    }
    
    //一括更新処理(本メソッド処理終了後にセッションのアクションフォームはクリアされます)
    @Execute(validator = false, removeActionForm = true)
    public String bulk_upd() {
        
        List<Employee> efs = new ArrayList<Employee>();
        for( EmployeeForm f : employeeForm.empUpdateItems ) {
            //更新対象フラグがtrueのものだけ更新します。
            if( f.update_check ) {
                Employee e = Beans.createAndCopy(Employee.class, f).execute();
                efs.add(e);
            }
        }
        //一括更新
        int[] countArray = employeeService.updateBatch(efs);
        return index();
    }

Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
 
 
 
-
|
|
import java.io.Serializable;
----
@Component(instance = InstanceType.SESSION)
public class EmployeeForm implements Serializable {
 
    private static final long serialVersionUID = 1L;
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
 
 
 
 
 
    //一覧の更新対象チェックボックス用
    public boolean update_check;
    
    //更新データ用
    public List<EmployeeForm> empUpdateItems;

Everything is expanded.Everything is shortened.
  1
  2
  3
-
|
!
    public int[] updateBatch(List<Employee> emps) {
        return this.jdbcManager.updateBatch(emps).execute();
    }
Everything is expanded.Everything is shortened.
  1
 
<input type="submit" name="edit_for_bulk_upd" value="一括更新" />
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<%@page pageEncoding="UTF-8" %>
<html>
<head>
<title>Tutorial: Employee List</title>
<link rel="stylesheet" type="text/css" href="${f:url('/css/sa.css')}" />
 
</head>
<body>
<h1>Tutorial: Employee List</h1>
 
<s:form>
<table border="1">
<tr style="background-color:pink">
<th>&nbsp;</th><th>Id</th><th>Name</th><th>JobType</th><th>Salary</th><th>Department</th><th>編集</th>
</tr>
<c:forEach var="e" varStatus="s" items="${empItems}">
<tr style="background-color:${s.index %2 == 0 ? 'white' : 'yellow'}">
<td><input type=checkbox name="delete_checks" value="${f:h(e.id)}"></td>
<td align="right">${f:h(e.id)}</td>
<td>${f:h(e.name)}</td>
<td>${f:h(e.jobType)}</td>
<td align="right"><fmt:formatNumber value="${e.salary}" pattern="#,##0"/></td>
<td>${f:label(e.departmentId, deptItems, "id", "name")}</td>
<td><s:link href="edit/${f:u(e.id)}">編集</s:link></td>
</tr>
</c:forEach>
</table>
 
<input type="submit" name="edit_for_add" value="追加" />
<input type="submit" name="delete" value="削除"/>
<input type="submit" name="edit_for_bulk_add" value="一括追加" />
<input type="submit" name="edit_for_bulk_upd" value="一括更新" />
</s:form>
 
</body>
</html>
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<title>Employee Bulk Insert</title>
</head>
<body>
<h4>一括編集</h4>
  <html:errors />
  <s:form>
    <table border="1">
        <tr>
            <th>&nbsp;</th>
            <th>Name</th>
            <th>JobType</th>
            <th>Salary</th>
            <th>Department</th>
        </tr>
        <c:forEach var="empUpdateItems" items="${empUpdateItems}">
            <tr>
                <td><html:checkbox name="empUpdateItems" property="update_check" indexed="true"/></td>
                <td><html:text name="empUpdateItems" property="name" indexed="true" /></td>
                <td><html:select name="empUpdateItems" property="jobType" indexed="true">
                    <html:option value="CLERK">CLERK</html:option>
                    <html:option value="SALESMAN">SALESMAN</html:option>
                    <html:option value="MANAGER">MANAGER</html:option>
                    <html:option value="ANALYST">ANALYST</html:option>
                    <html:option value="PRESIDENT">PRESIDENT</html:option>
                </html:select></td>
                <td><html:text name="empUpdateItems" property="salary" indexed="true" /></td>
                <td><html:select name="empUpdateItems" property="departmentId" indexed="true">
                    <html:option value=""></html:option>
                    <c:forEach var="d" items="${deptItems}">
                        <html:option value="${f:h(d.id)}">${f:h(d.name)}</html:option>
                    </c:forEach>
                </html:select></td>
            </tr>
        </c:forEach>
    </table>
    <br />
    <input type="submit" name="confirm_for_bulk_upd" value="更新内容確認" />
    <input type="submit" name="index" value="戻る"/>
  </s:form>
  </body>
</html>
Everything is expanded.Everything is shortened.
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<title>Employee List</title>
</head>
<body>
<h4>一括更新内容の確認</h4>
<s:form>
    <table border="1">
        <tr style="background-color: pink">
            <th>Name</th>
            <th>JobType</th>
            <th>Salary</th>
            <th>Department Name</th>
        </tr>
        <c:forEach var="e" varStatus="s" items="${empUpdateItems}">
          <c:if test="${e.update_check == true}">
            <tr>
                <td>${f:h(e.name)}</td>
                <td>${f:h(e.jobType)}</td>
                <td><fmt:formatNumber value="${e.salary}" pattern="#,##0" /></td>
                <td>${f:label(e.departmentId, deptItems, "id", "name")}</td>
            </tr>
          </c:if>
        </c:forEach>
    </table>
    <input type="submit" name="back_to_edit_for_bulk_upd" value="戻る" />
    <input type="submit" name="bulk_upd" value="一括更新" />
</s:form>
</body>
</html>

添付ファイル: fileemp_blk_upd5.jpg 409件 [詳細] fileemp_blk_upd4.jpg 437件 [詳細] fileemp_blk_upd3.jpg 337件 [詳細] fileemp_blk_upd2.jpg 462件 [詳細] fileemp_blk_upd1.jpg 584件 [詳細]

リロード   新規 編集 凍結解除 差分 添付 複製 名前変更   ホーム 一覧 単語検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS
Last-modified: 2012-08-08 (水) 23:26:10 (2925d)