开发者

Struts 2 s:submit button syntax to set values in map

I am browsing some Struts 2 code and I see this syntax for submit button that I haven't seen before..

<s:submit key="map.keyName$Value" />

It's not working (it was working with Struts 2.0.x now we have moved to Struts 2.2.3) any more. I mean its not setting the appropriate value based on the mentioned key in the map.

Has anyone used this syntax before?

Any other alternative syntax suggestions that will let me SET values in a map (using struts tag only) will be most welcome.

The jsp page containing this code is designed to be a decoupled component that can be included by any page at runtime that's why this page CAN开发者_运维百科NOT call any java code to set these values in java map - which is why i am looking for tag solution that can set values in the map.

thanks in advance


Set value in a map by :

In JSP only

OGNL assignment statement :

<s:set var="" value="map[key] = keyValue" /> 

Java

<s:set var="" value="map.put(key, keyValue)" /> 

EDIT

You could set value in map (to action class) with

<s:hidden name="map[key]" value="keyValue" />

by submit button with onclick attribute, for example (answer - assume multiple submit button) :

<script type="text/javascript">
    function setMap(key, keyValue) {
        document.getElementById("mapToSet").name="map['" + key + "']";
        document.getElementById("mapToSet").value=keyValue;
    }
</script>

<s:hidden name="test" id="mapToSet" />
<s:submit value="Search" onclick="setMap(key, keyValue)" />


I found this page when searching for "how to set values in a map in Struts2" and it led me to the following answer (which I understand is a little OT):


As an HTML input element:

<input type="hidden" name="myField[105]" value="myValue" />

This would populate an action variable declared as:

Map<Integer, String> myField;

such that:

myField.get(105).equals("myValue"); // == true
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜