2

I'm trying to create an "Hello World" JSF application. I have a bean with one field (String).

@ManagedBean (name = "beanTest")
@SessionScoped
public class BeanTest
{
    private String myString = "myString";
    public String getMyString()
    {
        return myString;
    }
    public void setMyString(String myString)
    {
        this.myString = myString;
    }
}

When I'm trying to display the string value in my JSP page

<h:outputLabel value="#{beanTest.myString}"/>

In the webpage it displayed "#{beanTest.myString}" instead of "myString"

How is this caused and how can I solve it?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
danieln
  • 4,285
  • 7
  • 36
  • 57

2 Answers2

2

That can happen if your web.xml is declared conform Servlet 2.4 or older, or if your /WEB-INF/lib folder is cluttered with servletcontainer specific libraries like el-api.jar, etc of an older version.

Make sure that the web.xml root declaraton conforms at least Servlet 2.5 or preferably the highest Servlet API version supported by your container and that the /WEB-INF/lib folder does not contain any servletcontainer specific libraries.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • So would this be because the app doesn't know how to handle EL expressions? – Zack Marrapese Apr 03 '12 at 14:04
  • @Zack: That's correct. The EL API has changed in Servlet 2.4 and 2.5. See also http://stackoverflow.com/questions/4812755/difference-between-jsp-el-jsf-el-and-unified-el for a bit of history. The OP's problem indicate that he's basically using an incompatible EL API and thus all expressions won't (can't) be resolved. – BalusC Apr 03 '12 at 14:06
  • You are right. I changed my web.xml from 2.4 to 2.5 and now everything works like a charm. How can I work with version 2.4? – danieln Apr 04 '12 at 06:37
  • Either downgrade to JSF 1.2 or provide your own EL implementation (I don't guarantee 100% that this hack will work in all containers): http://stackoverflow.com/questions/5998447/running-jsf-2-0-on-servlet-2-4-container/5998625#5998625) – BalusC Apr 04 '12 at 10:46
0

use h:outputtext for this purpose

Luke
  • 11,310
  • 43
  • 59
  • 67
Rahul Borkar
  • 2,586
  • 1
  • 20
  • 38