如何防止STRUTS持续选择?

时间:2013-01-17 23:00:59

标签: java struts struts-1 struts1

我正在使用JAVA STRUTS。我有一个带有与之关联的ActionForm类的html表单,并且使用标记创建控件。据我了解,STRUTS将在html表单上保留选择,即使表单已刷新。我需要阻止此行为并强制它从ActionForm对象重新绑定值。

基本上,我有一个带有单选按钮组的表单,允许用户选择A,B或C.我有一个ActionForm,在加载表单时设置属性“selection = A”。如果用户选择B并提交它,表单将正确设置为“selection = B”,一切都很好。但是,当我刷新页面时,ActionForm会重置为“selection = A”(通过调试确认),但单选按钮已选中B!

有谁知道为什么会这样或者我怎么能阻止它发生?

1 个答案:

答案 0 :(得分:0)

关于你的帖子,我认为它属于struts2所以,

According to struts2 it is not possible means, you have to give the static value or you have to make in programmatic manner through JPA (or)your java code

对于JPA,您可以参考此链接,这是有用的JPA way

This explanation is refer to static way

首先在jsp页面中,您必须import struts2 tagstaglib uri,然后它会显示您必须选择<s:radio></s:radio> tag

这些标记中的可用struts2标记
eg:
<s:radio label="Selections" name="your name" list="#{'A':'A','B':'B'}" value="2" />

在这段代码中我输入的值为2,因此如果你删除它不会选择任何默认值,它会选择B作为默认值。

Basically what i am trying to say here is without value it won't select any radio buttons 

you have to give value through static way or dynamic way.

对于动态方式,您可以参考此链接dynamic radio button