アイテムを作成するユーザーがいるJSPがあります。
作成後、更新と削除という2つのボタンとともに、テーブルの同じページにそれらを表示しています。
ユーザーが値を変更して[更新]をクリックすると、値が変更され、最初の行の列の値+変更された値がコンマで区切られて追加が表示されます。
なぜそれが起こっているのか、そしてそれを解決する方法を教えてもらえますか?
以下のjspファイルを見つけてください
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<script type="text/javascript">
function updateRow(id) {
var manufacturer = document.getElementById("manufacturer").value;
var family = document.getElementById("family").value;
var model = document.getElementById("model").value;
var url = "id="+id+"&manufacturer="+manufacturer+"&model="+model+"&family="+family;
document.globalForm.action= "http://localhost:8080/ContentInventory/update.action?id=" + id + "&manufacturer="+ manufacturer + "&model=" + model + "&family=" + family;
document.globalForm.submit();
}
function deleteRow(id) {
document.globalForm.action = "http://localhost:8080/ContentInventory/delete.action?id="+id;
document.globalForm.submit();
}
function addDetails() {
document.globalForm.action = "http://localhost:8080/ContentInventory/add.action";
alert(document.globalForm.action);
document.globalForm.submit();
}
</script>
<html>
<body>
<h1>Global Handset Compatibility</h1>
<s:actionerror />
<s:form id="globalForm" name="globalForm" method="post" theme="simple" >
<table>
<tr>
<td><s:label value="Manufacturer" />
</td>
<td><s:textfield name="manufacturer" label="Manufacturer" />
</td>
</tr>
<tr>
<td><s:label value="Model" />
</td>
<td><s:textfield name="model" label="Model" />
</td>
</tr>
<tr>
<td><s:label value="Family" />
</td>
<td><s:textfield name="family" label="Family" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<!--<s:submit value="Add Inventory" align="center" />-->
<input type="button" value="Add Inventory" id="addButton" onclick="javascript:addDetails()" >
</td>
</tr>
</table>
<h2>Inventory List</h2>
<table id="global" border="1" width="100%">
<tr>
<th>Manufacturer</th>
<th>Model</th>
<th>Family</th>
<th>Delete</th>
<th>Edit/Update</th>
</tr>
<s:if test="%{globalList.size() > 0}">
<s:iterator value="globalList" id="globals">
<tr>
<td align="center">
<s:textfield id="manufacturer" name="#globals.manufacturer" /></td>
<td align="center"><s:textfield id="model" name="#globals.model" /></td>
<td align="center"><s:textfield id="family" name="#globals.family" /></td>
<td align="center"><input type="button" value="Delete" id="deleteButton" onclick="javascript:deleteRow('<s:property value="id"/>')">
</td>
<td align="center">
<input type="button" value="Update" id="updateButton<s:property value="id"/>" onclick="javascript:updateRow('<s:property value="id"/>')">
</td>
</tr>
</s:iterator>
</s:if>
<s:else>
<tr>
<td colspan="5">No Data Found</td>
</tr>
</s:else>
</table>
</s:form>
</body>
</html>
そして、アクションクラスでは、フィールドのgetterメソッドとsetterメソッドがあり、[更新]ボタンをクリックすると、jsを使用して更新された値を取得し、バックエンドに送信します。値は正しく挿入されていますが、ページを表示している間、最初と2番目の値で区切られたコンマ付きの値も表示されます。これは正しくありません...
ご回答ありがとうございます