Method must have signature "String method() ...[etc]..." but has signature "void method()"
Asked Answered
H

1

67

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.

Hydrocarbon answered 10/11, 2011 at 17:8 Comment(0)
M
136

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:

Mammalogy answered 10/11, 2011 at 17:55 Comment(5)
thanks - you're a real genius :-) and I fully agree on your Eclipse verdict ;)Hydrocarbon
Thank you very much, this error was very frustrating... also I see that you're the same person who wrote those awesome tutorials I'm following, so thank you for that as well.Camisado
FYI: under IBM's pressure this Eclipse issue has finally been fixed this month.Mammalogy
@Mammalogy good it's fixed, sad it needed pressure from IBM. Clearly WTP developers don't use their own tools to build JSF apps!Dispirit
Based on your impressive answer, I believe changing the method signature to public String downloadItem(Item item) { ...; return null; } would make Eclipse happy without any change in app behavior, right?Dyeing

© 2022 - 2024 — McMap. All rights reserved.