@RequestMapping(value = "ok", method = RequestMethod.POST)
public String ok(@Validated TestForm form)
{
System.out.print("");
return "next";
}
@RequestMapping(value = "next")
public String next(Model model, String compCode, String compName)
{
System.out.print("");
model.addAttribute("compCode", compCode);
model.addAttribute("compName", compName);
return "next";
}
package com.mycompany.myapp.form;
import java.io.Serializable;
import java.util.List;
public class TestForm implements Serializable {
private static final long serialVersionUID = 1L;
private String test1;
private String test2;
private List<String> tableList;
public List<String> getTableList() {
return tableList;
}
public void setTableList(List<String> tableList) {
this.tableList = tableList;
}
public String getTest1() {
return test1;
}
public void setTest1(String test1) {
this.test1 = test1;
}
public String getTest2() {
return test2;
}
public void setTest2(String test2) {
this.test2 = test2;
}
}
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
<title>Home</title>
<script type="text/javascript"
src="${pageContext.request.contextPath}/resources/jquery-3.2.1.js"></script>
<link type="text/css" media="screen" href="${pageContext.request.contextPath}/resources/jquery-ui.min.css" rel="stylesheet" />
<link type="text/css" media="screen" href="${pageContext.request.contextPath}/resources/ui.jqgrid.css" rel="stylesheet" />
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/jquery.jqGrid.min.js" ></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/grid.locale-ja.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
alert("dddd");
var mydata = [
{comp_code:"CD1", comp_name:"株式会社シー", comp_kana:"カブシキカイシャシー"},
{comp_code:"CD2", comp_name:"ビー株式会社", comp_kana:"ビーカブシキカイシャ"},
{comp_code:"CD3", comp_name:"有限会社エー", comp_kana:"ユウゲンガイシャエー"},
];
jQuery("#list").jqGrid({
data: mydata,
datatype: "local",
colNames:['コード', '会社名', 'カナ'],
colModel:[
{name:'comp_code',formatter: function (cellvalue, options, rowObject) {
return '<a href="next/?compCode=' + rowObject.comp_code + '&compName=' + rowObject.comp_name + '" target="_blank">' +
cellvalue + "</a>";
}},
{name:'comp_name'},
{name:'comp_kana'},
],
multiselect: false,
caption: '会社一覧'
});
$("#selectBtn").click(function() {
var target = document.getElementById("gender");
alert(target.options[target.selectedIndex].text);
//alert($('select option:selected').text());
});
$("#okbtn").click(function() {
// グリッド内の選択されているデータを配列に取り込む
var rowIds = $("#list").getRowData().length;
if (rowIds == 0) {
alert("データを選択してください。");
return false;
}
var ret = confirm("選択した内容をサーバー保存します。よろしいですか?");
if (!ret) {
return false;
}
var tableList = [];
var values = new Array();
for (var i = 0; i < rowIds; i++) {
var row = $('#list').getRowData(rowIds[i]);
//values[i] = new Array(row.model, row.model_name);
tableList.push(row);
}
var gridData = jQuery("#list").getRowData();
//var postData = JSON.stringify(gridData);
var input = $("<input>").attr("type", "hidden").attr("name", "tableList").val(JSON.stringify(gridData));
/*
var inputObj = "";
inputObj = document.createElement("input");
$(inputObj).attr("type","hidden");
$(inputObj).attr('name','tableList');
$(inputObj).attr("value",JSON.stringify(tableList));
*/
//$('#TestForm').append($(inputObj));
$('#dynamic_form').append($(input));
//document.body.appendChild($('#TestForm'));
$("#TestForm").submit();
});
});
</script>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The time on the server is ${serverTime}. </P>
<table id="list">
</table>
<button id="okbtn" name="okbtn">ok button</button>
<select id="selectTest" name="selectTest" list="${name}"></select>
<input type="text" id="txtName" name="txtName" value="${name}">
<input id="selectBtn" type="button" value="selectButton">
<select id="gender" name="gender" class="style12">
<option selected="selected">ALL</option>
<option>Male Only</option>
<option>Female Only</option>
</select>
<form:form method="post" action="${pageContext.request.contextPath}/index/ok"
modelAttribute="testForm" id="TestForm" name="TestForm">
<input type="text" id="test1" name="test1" value="">
<input type="text" id="test2" name="test2" value="">
<input type="text" id="test3" name="test3" value="">
<div id="dynamic_form">
</div>
</form:form>
</body>
</html>
댓글 없음:
댓글 쓰기