Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf IntelliJ中的EL-out属性_Jsf_Intellij Idea_El - Fatal编程技术网

Jsf IntelliJ中的EL-out属性

Jsf IntelliJ中的EL-out属性,jsf,intellij-idea,el,Jsf,Intellij Idea,El,在intelliJ中,我得到以下代码的错误消息“EL out of attribute”: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://

在intelliJ中,我得到以下代码的错误消息“EL out of attribute”:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">

<h:body>
    <h1>JSF and Spring</h1>
    #{helloBean.hello()}
</h:body>
</html>

JSF与Spring
#{helloBean.hello()}
显然这是EL扩展的非标准用法,但我很难理解应该如何做。我的代码工作得很好,但我喜欢使用“正确”的方式,IntelliJ中的警告可能意味着我缺少了一些东西

我应该如何将其编写为“正确的”JSF2


严格地回答您的问题,为了“正确”,您可以这样写:

豆子:

@ViewScoped
public class HelloBean {
    public String getHello() {
        return "Whoa!";
    }
}
在你看来:

...
<h:body>
    #{helloBean.hello}
</h:body>
...
。。。
#{你好,你好}
...
尽管您可以像以前一样在EL 2.1+中调用方法,但早期版本的EL不允许这样做

在本例中,您可能会注意到,对于bean中名为
getHello
的方法,可以在没有
get
的情况下使用它,就像在
{helloBean.hello}
中一样,因为EL将找到该方法并隐式调用
get

关于IDE对看似正确的代码显示警告,您可以检查配置的项目库版本是否与实际要使用的版本匹配

例如,您希望使用JSF2.x,但项目设置为使用1.x。这可能会发生


我希望有帮助。

我也有同样的问题。我把#换成了$,IntelliJ就不再抱怨了可以在只读属性的情况下使用-我想IntelliJ强制执行更严格的语法。

我可能在这里错了,但是
out of attribute
建议您不应该在模板中的任何随机位置使用EL,而应该只在标记的属性中使用EL

这是比恩:

@ViewScoped
@ManagedBean
public class TestBean {
    private String message = "Hello world";

    public TestBean() {
        System.out.println("TestBean instantiated.");
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String fetchMsg() {
        return "Msg fetched: " + message;
    }
}
下面是XHTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>JSF Tutorial!</title>
</h:head>
<h:body>
    <!--No warning message-->
    <h:outputText value="#{testBean.message}"/>
    <h:outputText value="#{testBean.fetchMsg()}"/>

    <!--Warning message-->
    #{testBean.fetchMsg()}
</h:body>
</html>

JSF教程!
#{testBean.fetchMsg()}

使用Idea 14。

那么我最初写的是按照标准写的?但是IntelliJ错误地说它不是?我试过你说的,但IntelliJ也不喜欢那种方法。(请参阅更新的屏幕截图)您是否有一个带有getHello()方法的HelloBean?我会更新我的答案,让它更清晰。是的,我已经更新了,代码也可以运行了,但是我想知道我是否在用一种混乱的方式,因为IntelliJ抱怨它不符合属性。对不起,我注意到你在使用Spring。我从来没有使用过Spring,但我使用IntelliJ for JSF,从来没有遇到过这个问题。也许是关于你的项目设置。不。IntelliJ并不像它假装的那么聪明。顺便说一下,没有人是IDE。基本上,每一个面向Java的IDE在如何验证EL方面都有相当大的失败。只需阅读jcp.org上的EL规范,了解如何编写有效的EL,然后在IDE中禁用EL验证以避免麻烦。更多阅读: