有没有办法将OGNL与Struts2 UI标签绑定 [英] Is there a way to bind OGNL with Struts2 UI tags

查看:108
本文介绍了有没有办法将OGNL与Struts2 UI标签绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Struts2开发一个Webapp.我曾经与Struts1合作

I'm developing a webapp using Struts2. I used to work with Struts1

有一种直接将会话对象引用到JSP的方法,这样,如果我更改公式器中的值,被引用的会话对象中的值也将被更新.

is there a way to reference a session object directly to the JSP so that if I change the value in the formular, the value in the referenced session object will also be updated.

<s:textfield name="%{#session.order.amount}"/>

例如我有一个会话对象订单,该订单对象的属性带有getter和setter.

for e.g. I have a session object order which has attribute amount with getter and setter.

在我将一些值放入textfield然后提交页面之后,会话中的值似乎没有更新.

it seems like, after I put some values into the textfield and then submit the page, the value in the session didn't get updated.

当前,我正在使用另一种方法,该方法涉及在动作属性的设置器内包含session.put().我个人不喜欢当前的解决方案.

currently I'm using another approach which involves session.put() inside the setter of an action attributes. Personally I dislike my current solution.

推荐答案

您可以尝试将名称命名为 string session.order.amount,并使您的操作实现SessionAware,并公开会话.当前,您正在将名称设置为session.order.amount value .

You could try having the name be the string session.order.amount and make your action implement SessionAware, and expose the session. Currently you're setting the name to the value of session.order.amount.

我不知道它是否行得通,您可能需要使用数组/集合符号,但是我不知道为什么它行不通.

I don't know if it would work, and you might need to use array/collection notation, but off the top of my head I don't know why it wouldn't work.

也就是说,我觉得直接将视图层写入到Web应用程序内部是一个坏主意.

That said, I feel like direct view-layer writes into web app internals is a Bad Idea.

这篇关于有没有办法将OGNL与Struts2 UI标签绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆