Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EL out of attribute in IntelliJ

In intelliJ I get the error message "EL out of attribute" for the following code:

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

apparently this is nonstandard usage of EL extension, but I am having a hard time understanding how I should do this instead. The code I have works just fine, but I like use the "correct" way, and warnings in IntelliJ probably means there is something I am missing.

How should I have written this to be "correct" JSF 2?

enter image description here

enter image description here

like image 531
Vegard Avatar asked Sep 12 '25 22:09

Vegard


2 Answers

I might be wrong here, but out of attribute suggest you shouldn't use EL in any random place in your template, but within tag's attribute only.

Here's 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;
    }
}

Here's 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>

Using Idea 14.

like image 145
wst Avatar answered Sep 16 '25 02:09

wst


I had the same issue. I replaced the # with a $ and the IntelliJ no longer complained. $ can be used in the case of read only attributes - I guess IntelliJ enforces a stricter syntax.

like image 45
dbarton_uk Avatar answered Sep 16 '25 00:09

dbarton_uk