1

I am new in JSF and my first JSF 2.2 application is giving me some errors that i don't understand. This is how the application works::

A user will type a text in the form.xhtml file and the text he entered will be displayed in the result.xhtml file.

When form.xhtml displays when the application lunches i want to display a message at the top of the form. The message comes from a default value in an instance variable that is in the managed bean.

It is displaying the text from the instance variable that is given me problems now. I don't understand why displaying a default text from instance variable gives me problems.

I'm using elclipse and glassfish now

This is the managed bean:

@ManagedBean
public class Navigator {

    private String name;
    private String defaultMsg = "THIS IS MY DEFAULT MESSAGE";

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    public String getDefaultMsg() {
        return defaultMsg;
    }
    public void setDefaultMsg(String defaultMsg) {
        this.defaultMsg = defaultMsg;
    }
}

I have two xhtml files ::

// form.xhtml
<?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>
        <h:outputText value="#{navigator.defaultMsg}" />
    <h:form>
        <h:inputText value="#{navigator.name}" />
        <h:commandButton value="Say Hello" action="result" />
    </h:form>

</h:body>

</html>


// result.xhtml
<?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>
    <h3>Hello #{navigator.name} !</h3>
</h:body>

</html>

This is the problem i don't understand:: When i run my code without <h:outputText value="#{navigator.defaultMsg}" /> in form.xhtml, everything works fine. But if include that portion in the file, i get this error in the brower::

exception

javax.servlet.ServletException: /form.xhtml @8,51 value="#{navigator.defaultMsg}": The class 'jsf.Navigator' does not have the property 'defaultMsg'.
root cause

javax.el.PropertyNotFoundException: /form.xhtml @8,51 value="#{navigator.defaultMsg}": The class 'jsf.Navigator' does not have the property 'defaultMsg'.
note The full stack traces of the exception and its root causes are available in the Oracle GlassFish Server 3.1.2.2 logs.

The class 'jsf.Navigator' does not have the property 'defaultMsg'.

jsf is the name of the project and Navigator is the class name

What i don't understand is how come the instance variable defaultMsg is in the class but it can't recognized it. Does it have to do with the way managed beans are initialized?

Need some little explanation to know why.

thanks guys

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Eddy Freeman
  • 3,059
  • 6
  • 27
  • 46

0 Answers0