Java struts2 <s:select...> 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/724325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
struts2 <s:select...> tag
提问by Nirmal
I have simple user registration form. In which i am puting city as a tag. Here drop down box value coming from city master table from mysql database.
我有简单的用户注册表。其中我将城市作为标签。这里的下拉框值来自 mysql 数据库的 city master 表。
But when i storing whole user registration values, i m not be able to fetch currently selected city value. Can anyone help me...? My user registration form contains :
但是当我存储整个用户注册值时,我无法获取当前选择的城市值。谁能帮我...?我的用户注册表包含:
<s:form action="UserAction" >
<s:textfield name="name" label="User Name" />
<s:textfield name="age" label="Age" />
<s:radio name="sex" label="Sex" list="{'M','F'}" />
<s:select list="cities" key="cities.name" listValue="name">
</s:select>
<s:submit />
</s:form>
采纳答案by Nirmal
Finally got the solution after writing following code :
编写以下代码后终于得到了解决方案:
<s:select list="cities" name="city">
<s:iterator value="cities">
</s:iterator>
</s:select>
And at the time of insertion through DAO, it will automatically fetching all the value from bean.
并且在通过 DAO 插入时,它会自动从 bean 中获取所有值。
回答by Adeel Ansari
Give your list the exact name what you have in your bean, in your case city. It should start working now.
在您的案例中,为您的列表提供您在 bean 中拥有的确切名称city。它现在应该开始工作了。
回答by nathj07
In your action class you are probably have an attribute based on the select tag. When you set this value add an annotation above the method signature.
在您的操作类中,您可能有一个基于 select 标签的属性。当您设置此值时,在方法签名上方添加一个注释。
Something like:
就像是:
@RequiredStringValidator(type = ValidatorType.SIMPLE, message = "Please select a value", fieldName = "select")
This should sort you out. This can also be done within the struts.xml file in a fairly similar way.
这应该让你理清头绪。这也可以以相当类似的方式在 struts.xml 文件中完成。
Cheers Nathan
干杯弥敦道