2012-02-23 5 views
0

複数のPersonエンティティを1つのHTMLフォームに挿入したいとします。私はMap<Integer, Person>をActionクラスのプロパティとして使いたいです。このためのフォーム入力パラメータ名は何か。 Personの属性は、ID、名前、年齢です。単一のフォームから複数のエンティティを挿入する

<form action="createPeople"> 
//person1 
    <input type='text' name='{What is the name here?}' /> 
    <input type='text' name='{What is the name here?}' /> 
    <input type='text' name='{What is the name here?}' /> 

//person2 
    <input type='text' name='{What is the name here?}' /> 
    <input type='text' name='{What is the name here?}' /> 
    <input type='text' name='{What is the name here?}' /> 
</form> 

答えて

1

次に、コンテンツをマップに挿入する例を示します。

<%@taglib prefix="s" uri="/struts-tags"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <body> 
     <h1>Input Test</h1> 
     <s:form action="test"> 
      <s:textfield size="40" name="myMap[1]"></s:textfield><br/> 
      <s:textfield size="40" name="myMap[2]"></s:textfield><br/> 
      <s:textfield size="40" name="myMap[33]"></s:textfield><br/> 
      <s:textfield size="40" name="myMap[444]"></s:textfield><br/> 
      <s:textfield size="40" name="myMap[999]"></s:textfield><br/> 
      <s:submit/> 
     </s:form> 
    </body> 
</html> 

アクション... Struts2のは、型変換

package com.quaternion.struts2basic.action.test; 

import com.opensymphony.xwork2.ActionSupport; 
import java.util.HashMap; 
import java.util.Map; 

public class Test extends ActionSupport{ 
    //public to make example shorter 
    public Map<Integer, String> myMap = new HashMap<Integer, String>(); 

    public String exectute(){ 
     return SUCCESS; 
    } 
} 

警告のためにジェネリック医薬品を利用することができます...次はあなたがそれは、[1]数

として扱われている期待し
<s:textfield size="40" name="myMap[1]"></s:textfield><br/> 

['1']は文字として扱われますが、 '22'は文字列に変換されるため、 '22'は22に変換されますが、 '1'それはおそらくあなたが何をしているのではないnt。

[「1」]は動作しますが、支柱になっ書かれたHTMLタグを付ける必要があります。

<input type="text" name="myMap[&quot;1&quot;]" size="40" value="" id="test_myMap_&quot;444&quot;_"/><br/> 

動作しません。

関連する問題