简体   繁体   English

Struts 2 s:提交按钮语法以设置地图中的值

[英]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.. 我正在浏览一些Struts 2代码,并且看到了以前从未见过的Submit按钮的语法。

<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. 它不再起作用了(它已经与Struts 2.0.x一起使用了,现在我们已经迁移到Struts 2.2.3了)。 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. 我们将欢迎其他任何可让我在地图中设置值的语法建议(仅使用struts标记)。

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 CANNOT 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. 包含此代码的jsp页面被设计为一个解耦的组件,可以在运行时包含在任何页面中,这就是为什么该页面无法调用任何Java代码来在Java映射中设置这些值的原因-这就是为什么我正在寻找可以在地图上设置值。

thanks in advance 提前致谢

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): 我在搜索“如何在Struts2中的地图中设置值”时找到了此页面,它使我想到了以下答案(据我了解,这有点过时):


As an HTML input element: 作为HTML输入元素:

<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

Set value in a map by : 通过以下方式在地图中设置值:

In JSP only 仅在JSP中

OGNL assignment statement : OGNL分配声明:

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

Java 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) : 例如,按具有onclick属性的提交按钮( 答案 -假设有多个提交按钮):

<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)" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM