jsf - IntelliJ 中的 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://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>

显然这是 EL 扩展的非标准用法,但我很难理解我应该如何做到这一点。我的代码工作得很好,但我喜欢使用“正确”的方式,IntelliJ 中的警告可能意味着我遗漏了一些东西。

我应该如何将其编写为“正确”的 JSF 2?

enter image description here

enter image description here

最佳答案

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

这是 bean :

@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>

使用想法 14。

关于jsf - IntelliJ 中的 EL 属性不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21368045/

相关文章:

python - Intellij 不断重新排序我的 `import os`

jsf-2 - 如何将方法参数传递给 ActionListener?

java - 为什么 SpEL 不支持 unicode 变量?如何解决?

java - 如何在 jSTL 中使用三元运算符编写 if else 条件?

jsf - 如何让JSF render 严格符合XHTML 1.0?

java - JSF 中的自刷新组件

image - 如何在 JSF + Primefaces 3.2 中渲染图像

jsf - session 结束时销毁 View 范围的bean

intellij-idea - 在 IntelliJ IDEA 中使用命名捕获组替换

ant - 为 ant 脚本设置环境变量