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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With