Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

eclipse - Method must have signature "String method() ...[etc]..." but has signature "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>

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...