我想使用一个有两个提交按钮的表单。每个按钮调用相同的表单操作,但为其中一个字段提交不同的值。为此,我成功使用了s:submit按钮,如下所示:
<s:submit name="submitType" value="foo" type="button">Click me!</s:submit>
在上面,按钮中显示的文本(“Click me!”)与表单提交的值(“foo”)不同。但是,具有完全相同属性的dojo submit标记不是这种情况:
<sx:submit name="submitType" value="bar" type="button">Or click me!</sx:submit>
使用上面的标签,按钮的文字是“bar”,单词“Or click me!”出现在旁边。
为了更好地衡量,我将引入由每个按钮生成的HTML:
<!-- (Using the simple form theme) -->
<!-- The s:submit tag: -->
<button type="submit" id="submit-sandbox_submitType" name="submitType"
value="foo">
Click me!
</button>
<!-- The sx:submit tag -->
<input type="button" dojoType="struts:Bind" events="onclick"
id="widget_1100841481" label="bar" name="submitType" value="bar" />
<script language="JavaScript" type="text/javascript">
djConfig.searchIds.push("widget_1100841481");
</script>
Or click me!
似乎sx:submit按钮的type属性无法正常工作,因为它在文档中有描述! :(有什么想法吗?
答案 0 :(得分:0)
我在Struts 2食谱中找到了自己问题的答案。当您使用多个提交按钮输入提交不同的字段值时,建议的方法是为每个提交按钮使用单独的布尔字段,而不是为所有提交按钮使用单个字符串字段。这样,按钮的value属性与提交给动作的内容无关,所以我可以用它来显示我想要的任何文本。
http://struts.apache.org/2.2.3/docs/multiple-submit-buttons.html