1

アクションクラス

public class ProductAction extends ActionSupport implements Preparable {
    private Document product;
}

モデル

public class Document {
    private Map<String, Object> properties;
}

JSP

<s:textfield name="product.properties.PRODUCT_NAME" 
             value="%   {product.properties..PRODUCT_NAME}" 
             label="%{getText('label.PRODUCT_NAME')}" size="40" />

<s:textfield name="product.properties.SUPPLIER" 
             value="%{product.properties.SUPPLIER}" 
             label="%{getText('label.SUPPLIER')}" size="40" />

Product_name と Supplier は、Map ( Map<String, String[]>) プロパティの配列として取り込まれます。

PRODUCT_NAME : [Ljava.lang.String;@4e96ac47]
SUPPLIER     : [Ljava.lang.String;@1c90a278]

Document->properties を変更すると、正常にMap<String, String>動作します。

Map<String, Object>しかし、他のデータ型のためにDocument->properties を保持したいと思います。

この問題を解決するには、フォーム データをStringではなくとして入力する必要がありString[]ます。

同じ名前のテキスト フィールドが複数ありません。

4

4 に答える 4

0

モデルを変更し、Map を操作するメソッドを導入しますが、以下のようにデータを基になる Map に保存します

public class Document {
    private Map<String, Object> properties;


    public Map<String, String> getStringProperties() {
        //logic to populate Map<String, String>
        return new HashMap<String, String>();
    }

    public void setStringProperties(Map<String, String> stringProperties) {
        properties.putAll(stringProperties);
    }
}

jsp では、以下のように stringProperties を使用します

<s:textfield name="product.stringProperties.SUPPLIER" 
             value="%{product.stringProperties.SUPPLIER}" 
             label="%{getText('label.SUPPLIER')}" size="40" />
于 2013-06-14T18:02:46.610 に答える
0

これを試して

<s:textfield name="product.properties.SUPPLIER" 
             value="%{product.properties.SUPPLIER[0]}" 
             label="%{getText('label.SUPPLIER')}" size="40" />

これにより、配列の最初のアイテムが取得されます

于 2013-06-12T09:20:50.847 に答える
0

解決策: 型コンバーターを Bean またはモデルに適用できます http://struts.apache.org/release/2.3.x/docs/type-conversion.html#TypeConversion-ApplyingaTypeConvertertoabeanormodel

于 2013-06-19T06:51:52.443 に答える
0

Element アノテーションを使用することは、これを記述するよりもはるかに簡単ですTypeConverter

@Element( value = java.lang.String.class )
private Map<String, Object> properties;
于 2017-06-29T16:23:09.313 に答える