struts 2 将属性标签的值分配给隐藏字段 [英] struts 2 assigning value of property tag to hidden field

查看:29
本文介绍了struts 2 将属性标签的值分配给隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将字段描述中的值分配给隐藏字段测试.但问题是描述"包含单词序列,以下代码仅将第一个单词分配给测试"

I want to assign the value from field Description to a hidden field test. But the problem is the "Description" contains sequence of words and the following code is assigning only first word to "test"

name="test">

我对 struts 有点陌生.有人可以帮忙吗.如果我能了解 struts2 的良好教程链接,那就太好了.

I am kind of new to struts. Can someone please help. Also it would be nice if i get to know good tutorial links of struts2.

推荐答案

如果这是你的动作类中的一个属性,你不需要使用 <s:property value="Description"/> 因为 Description 将位于值堆栈的顶部,您可以使用 OGNL 从值堆栈中获取值.这就是您需要做的

If this is a property in your action class you need not to use <s:property value="Description" /> as the Description will be available at the top of value stack and you can use OGNL to fetch the value from value-stack.This is what you need to do

<s:hidden  value="%{description}" name="test" />

请确保隐藏字段中的 value 应该与您的操作类中的属性名称相似,因为它将被解析为您的操作类中的 getter 和 setter 或定义的公共属性在你的行动中.

Please make sure the value in hidden filed should be similar to the name of property in your action class as it will be resolved to either the getter and setter in your action class or the public property defined in your action.

所以这意味着 value="%{description}" 会像 getDescription() 一样被 OGNL 转换,并且会尝试在你的 action 类中找到 getter 来获取属性值.

So this means value="%{description}" will be converted by OGNL like getDescription() and will try to find the getter in your action class to fetch the property value.

这篇关于struts 2 将属性标签的值分配给隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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