JSP 中 Struts2 映射条目的字段名称
我想从 JSP 填充 Struts2 操作的地图属性。 我应该使用什么格式的数据名称? 最初我对填充 Map
I want to populate a map property on a Struts2 action from a JSP. What is the format of the data names that I should use? Initially I am interested in populating a Map<String, String> but in the future I would be interesting in populating a Map<String, DomainClass> where the DomainClass has properties of its own.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我有一个操作,其属性如下 -
要在地图上设置值,基本上有两个步骤。 首先,OGNL 无法实例化地图,因此这取决于您。 在我的操作中,我实现了 Preparable 接口,但在运行“public String input()”方法之前实例化它,如下所示 -
现在,该对象是非空的,我可以在 JSP 中使用类似于以下的语法 -
迭代器从堆栈中取出一组对象并对其进行迭代。 重要的部分是“name=”部分,请注意双转义的单引号。 这样,当页面呈现时,输入元素的名称将变为(例如)- assetProps['Screen Size']。 当页面提交时,在“public voidexecute()”方法中,assetProps 被完全填充。
I have an action, with a property as follows -
To set values onto the map, there are basically two steps. First off, OGNL can't instantiate the map, so it is up to you. In my action, I implement the Preparable interface, but instantiate it before running the 'public String input()' method as follows -
Now, the object is non-null, I can use syntax similar to the following in the JSP -
The iterator pulls a set of objects off the stack and iterates over it. The important part is the "name=" section, notice the double-escaped single quotes. That way, when the page renders, the name of the input element becomes (for example) - assetProps['Screen Size']. When the page is submitted, inside the "public void execute()" method, assetProps is fully populated.
这是另一个执行类似操作的代码片段,以防它对某人有帮助。
我的操作有一个名为
storageIds
的Map
迭代 Map 时,键和值解析为
Map.Entry
属性。Here is another code snippet doing something similar, in case it helps someone.
My action has a
Map<String,String>
namedstorageIds
When iterating a Map, key and value resolve to the
Map.Entry
properties.尝试这个 。 非常适合我
Try This . Working perfectly for me