Eclipse 对 JSF 文件中的 EL 表达式给出了过多的错误错误和警告

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28605864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:24:56  来源:igfitidea点击:

Eclipse gives too many false errors and warnings on EL expressions in JSF files

eclipsevalidationjsfel

提问by adbdkb

I have run into a weird situation. I have an application which was originally developed in RAD and uses a construct like

我遇到了一个奇怪的情况。我有一个最初在 RAD 中开发的应用程序,并使用了类似的结构

rendered="#{bean.show and user.can('foo')}"

Our developers use mix of RAD and Eclipse Juno / Kepler. So we need to make the code work in both the environments.

我们的开发人员混合使用 RAD 和 Eclipse Juno / Kepler。所以我们需要让代码在这两种环境中都能工作。

In RAD, the above line does not generate any errors. When I export the project as archive and import it into Eclipse Juno, it generates this error

在 RAD 中,以上行不会产生任何错误。当我将项目导出为存档并将其导入 Eclipse Juno 时,它会生成此错误

Cannot apply expression operators to method bindings

不能将表达式运算符应用于方法绑定

Our environment is Websphere 8.5, RAD / Eclipse, JSF 2.1

我们的环境是 Websphere 8.5、RAD/Eclipse、JSF 2.1

How can I fix this?

我怎样才能解决这个问题?

回答by BalusC

In general, if you face a false EL validation error in a JSF file in Eclipse, try peeking around in Window > Preferences > Web > JavaServer Faces Tools > Validationand tune some settings currently (unnecessarily) set at Error.

通常,如果您在 Eclipse 中的 JSF 文件中遇到错误的 EL 验证错误,请尝试在Window > Preferences > Web > JavaServer Faces Tools > Validation 中查看并调整当前(不必要)在Error 中设置的一些设置。

enter image description here

在此处输入图片说明

Your particular problem is triggered by "Applying operator to method binding" which indeed defaults to Error. If upgrading Eclipse to most recent version is somehow not an option, setting it back to Warningshould tone down it.

您的特定问题是由“将运算符应用于方法绑定”触发的,它确实默认为Error。如果将 Eclipse 升级到最新版本在某种程度上不是一种选择,则将其重新设置为“警告”应该会减弱它。

After all, EL validation in Eclipse is quite an epic fail. It seems like it's using regular expressions to validate EL syntax instead of a true stack based parser like as EL itself is doing. There are several entries below "Type Coercion Problems" and "Type Assignment Problems" which are unnecessarily set to Errorand known to cause false errors.

毕竟,Eclipse 中的 EL 验证是一场史诗般的失败。似乎它正在使用正则表达式来验证 EL 语法,而不是像 EL 本身所做的那样使用真正的基于堆栈的解析器。在“Type Coercion Problems”和“Type Assignment Problems”下面有几个条目被不必要地设置为错误并且已知会导致错误错误。

See also:

也可以看看:

回答by JoseA

I had the same error with any of these statements:
<h:panelGroup rendered="#{!bean.isValid(obj)}"> <h:panelGroup rendered="#{not bean.isValid(obj)}">

我对这些陈述中的任何一个都有同样的错误:
<h:panelGroup rendered="#{!bean.isValid(obj)}"> <h:panelGroup rendered="#{not bean.isValid(obj)}">

I resolved the error by changing the statement as follows:
<h:panelGroup rendered="#{bean.isValid(obj) == false}">

我通过如下更改语句解决了错误:
<h:panelGroup rendered="#{bean.isValid(obj) == false}">

I found yet another example that resolved the problem:
<ui:fragment rendered="#{bean.isValid(obj) eq 'false'}">

我发现了另一个解决问题的例子:
<ui:fragment rendered="#{bean.isValid(obj) eq 'false'}">