方法必须具有签名“String method() ...[etc]...";但有签名“void method()" [英] Method must have signature "String method() ...[etc]..." but has signature "void method()"

查看:27
本文介绍了方法必须具有签名“String method() ...[etc]...";但有签名“void method()"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

在支持 bean 中有这个方法:

In the backing bean there's this method:

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

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

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

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

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()"

我能做什么?

如果相关,我将在 Tomcat 7 上使用 Eclipse Indigo SR1.

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

推荐答案

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

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).

图片借自 此博客 诚挚的.

Image borrowed from this blog in all courtesy.

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

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 ;)

此问题已在 Eclipse Luna SR1 中修复,距报告该问题已近 6 年.严重性已从 Error 降低到 Warning.您可能仍想将其设置为忽略.

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.

这篇关于方法必须具有签名“String method() ...[etc]...";但有签名“void method()"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆