方法必须具有签名“String method() ...[etc]...”但具有签名“void method()”

发布于 2024-12-14 14:51:43 字数 1545 浏览 2 评论 0原文

我有一个数据表,每行都有一个按钮:

<ice:dataTable ... var="item">
  <ice:column>
    <h:commandButton value="Download" action="#{mybean.downloadItem(item)}" />
  </ice:column>
</ice:dataTable>

在支持 bean 中有这个方法:

public void downloadItem(Item item) {
    // ...
}

一切正常(单击时执行该方法),但是 Eclipse 验证失败并显示以下奇怪消息:

方法必须具有签名“String method(), String method(), String 方法(字符串),字符串方法(字符串,字符串),字符串方法(字符串, 字符串,字符串),字符串方法(字符串,字符串,字符串,字符串),字符串 方法(字符串,字符串,字符串,字符串,字符串),字符串方法(字符串, 字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串, 字符串,字符串,字符串,字符串,字符串),字符串方法(字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串),字符串方法(字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串), 字符串方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串),字符串方法(字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串 方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串),字符串方法(字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串),字符串方法(字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串),字符串方法(字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串),字符串 方法(字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, 字符串,字符串,字符串,字符串,字符串,字符串,字符串,字符串, String, String, String)”,但具有签名“void method()”

我能做什么?

如果相关的话,我在 Tomcat 7 上使用 Eclipse Indigo SR1。

I have a datatable with a button in each row:

<ice:dataTable ... var="item">
  <ice:column>
    <h:commandButton value="Download" action="#{mybean.downloadItem(item)}" />
  </ice:column>
</ice:dataTable>

In the backing bean there's this method:

public void downloadItem(Item item) {
    // ...
}

Everything works fine (when clicked the method is executed), but
Eclipse validation fails with this strange message:

Method must have signature "String method(), String method(), String
method(String), String method(String, String), String method(String,
String, String), String method(String, String, String, String), String
method(String, String, String, String, String), String method(String,
String, String, String, String, String), String method(String, String,
String, String, String, String, String), String method(String, String,
String, String, String, String, String, String), String method(String,
String, String, String, String, String, String, String, String),
String method(String, String, String, String, String, String, String,
String, String, String), String method(String, String, String, String,
String, String, String, String, String, String, String), String
method(String, String, String, String, String, String, String, String,
String, String, String, String), String method(String, String, String,
String, String, String, String, String, String, String, String,
String, String), String method(String, String, String, String, String,
String, String, String, String, String, String, String, String,
String), String method(String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String), String method(String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String), String method(String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String), String method(String, String, String,
String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String), String
method(String, String, String, String, String, String, String, String,
String, String, String, String, String, String, String, String,
String, String, String)" but has signature "void method()"

What can I do?

If that's relevant, I'm using Eclipse Indigo SR1 on Tomcat 7.

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

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

发布评论

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

评论(1

凌乱心跳 2024-12-21 14:51:43

忽略它。 Eclipse 是个混蛋。您可以通过设置窗口>来调整它。首选项>网页> JavaServer Faces 工具 >验证>类型分配问题>方法表达式签名与警告忽略不兼容(默认为错误)。

输入图像描述这里

图片借自此博客,谨此致谢。< /sup>

原因是,Eclipse 希望 action 属性始终返回 String,而不是 void。虽然 JSF action 属性中确实未指定,但 EL 方法表达式本身实际上也支持 void 方法。过分热心的消息反过来表明,负责此验证的底层逻辑无法确定各个方法参数,因此它尝试将原始方法签名与允许的签名集合进行比较,如果没有匹配,则最终会在消息中显示成立。根据该消息,当该方法具有 20 个或更多参数时,此问题也可能会消失;)

在报告该问题近 6 年后,该问题已在 Eclipse Luna SR1 中得到修复。严重性已从错误降低到警告。您可能仍想将其设置为忽略

另请参阅:

Ignore it. Eclipse is a jerk. You can tone it by setting Window > Preferences > Web > JavaServer Faces Tools > Validation > Type Assignment Problems > Method expression signature incompatibility to Warning or Ignore (it defaults to Error).

enter image description here

Image borrowed from this blog in all courtesy.

The reason is, Eclipse expect the action attribute to always return String, not void. Whilst indeed unspecified in JSF action attribute, the EL method expressions themselves actually also support void methods. The overzealous message in turn suggests that the underlying logic responsible for this validation is incapable of determining the individual method arguments and thus it tries to compare the raw method signature against a collection of allowed signatures, which ultimately get shown in the message if no match was found. Based on the message, this problem may also disappear when the method has 20 or more arguments ;)

This is fixed in Eclipse Luna SR1, nearly 6 years after the issue was reported. The severity has been decreased from Error to Warning. You may still want to put it yet lower to Ignore.

See also:

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