Struts2中的多个提交按钮问题

发布于 2024-10-10 02:44:00 字数 592 浏览 4 评论 0原文

尝试在 struts2 应用程序中的单个表单中使用多个提交按钮,但无法工作。 这是我使用的jsp代码,

<tr>
<td class="button"><input type="submit" value="Import"
        name="destinationImport" class="button"></td>
    <td class="button"><input type="submit" value="Export"
        name="destinationExport" class="button"></td>
</tr>

这里是java部分

private boolean destinationImport;
private boolean destinationExport;
//and the respective setters and getters

,但我确信Struts2类型转换器在将字符串值转换为布尔值时遇到问题 有人知道如何实现这一目标吗?

提前致谢

Trying to work with multiple submit buttons within a single form in struts2 application but not able to work.
here is the jsp code i am using

<tr>
<td class="button"><input type="submit" value="Import"
        name="destinationImport" class="button"></td>
    <td class="button"><input type="submit" value="Export"
        name="destinationExport" class="button"></td>
</tr>

here is the java part

private boolean destinationImport;
private boolean destinationExport;
//and the respective setters and getters

but i am sure is that Struts2 type convertor is having problem converting the String value to boolean
do any one have idea how to achieve this

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛溺水了 2024-10-17 02:44:00

方法: getDestinationExport / setDestinationExport 应该处理字符串,因为您的值:“Export”和“Import”不能直接转换为布尔类型。
如果需要通过内部规则进行转换,请将相应的代码放在setDestinationExport中。像这样的东西:

 public void setDestinationExport(String arg){
     destinationExport = "Export".equals(arg);
     destinationImport = "Import".equals(arg);
 }

Methods : getDestinationExport / setDestinationExport should deal with String, since your values: "Export" and "Import" aren't convertible directly to boolean type.
If you need convert it by internal rule, place corresponding code inside setDestinationExport. Something like that:

 public void setDestinationExport(String arg){
     destinationExport = "Export".equals(arg);
     destinationImport = "Import".equals(arg);
 }
一曲琵琶半遮面シ 2024-10-17 02:44:00

这种方式应该有效

private boolean destinationImport = false;
private boolean destinationExport = false;

public void setDestinationImport(boolean destinationImport) {
  this.destinationImport = true;
}

public void setDestinationExport(boolean destinationExport) {
  this.destinationExport = true;
}

参考:
http://serpensalbus.com/blog/tricking-struts2-multiple-submit-按钮/

This way should works

private boolean destinationImport = false;
private boolean destinationExport = false;

public void setDestinationImport(boolean destinationImport) {
  this.destinationImport = true;
}

public void setDestinationExport(boolean destinationExport) {
  this.destinationExport = true;
}

Reference:
http://serpensalbus.com/blog/tricking-struts2-multiple-submit-buttons/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文