Error getting property ... from bean of type ...

Hi, I'm working on a jsf login form with database connectivity.

But I'm stuck on an error I get.

exception

org.apache.jasper.JasperException: javax.servlet.jsp.JspException: Error getting property 'username' from bean of type mct.data.mbeans.EnqueteMBean

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)

com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)

com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)

here's my index.jsp code:

<f:view>

<h:form>

<h:panelGrid columns="3">

<h:outputText value="Gebruikersnaam: " />

<h:inputText id="username" value="#{EnqueteMBean.newGebruiker.username}" required="true" />

<h:message for="username" style="color: #FFCC33;" />

<h:outputText value="Wachtwoord: " />

<h:inputSecret id="password" value="#{EnqueteMBean.newGebruiker.password}" required="true" />

<h:message for="password" style="color: #FFCC33;" />

<h:commandButton action="#{EnqueteMBean.checkLogin}" value="Inloggen" />

</h:panelGrid>

</h:form>

</f:view>

Here's my mbean code:

public class EnqueteMBean {

private Gebruiker newGebruiker;

public EnqueteMBean() {

System.out.println("ENQUETEMBEAN");

this.setNewGebruiker(new Gebruiker());

}

public String checkLogin() {

System.out.println(" BEGIN CHECK LOGIN -");

System.out.println("USERNAME: " + this.getNewGebruiker().getUsername());

System.out.println("PASSWORD: " + this.getNewGebruiker().getPassword());

System.out.println(" END CHECK LOGIN -");

EnqueteDAO dao = new EnqueteDAO("root","mypassword","jdbc:mysql://localhost/enquete");

String userExists = dao.checkUsername(this.getNewGebruiker().getUsername());

if(userExists == "usernameExists"){

System.out.println("-- BEGIN LOGIN --");

System.out.println("username: " + this.getNewGebruiker().getUsername());

System.out.println("password: " + this.getNewGebruiker().getPassword());

System.out.println("-- END LOGIN --");

return "loginCorrect";

}

else{

System.out.println("-- LOGIN FAILED --");

return "loginIncorrect";

}

}

public Gebruiker getNewGebruiker() {

return newGebruiker;

}

public void setNewGebruiker(Gebruiker newGebruiker) {

this.newGebruiker = newGebruiker;

}

}

Here's my Gebruiker.java code:

public class Gebruiker {

private String username;

private String password;

public Gebruiker() {

System.out.println("NEW GEBRUIKER");

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

System.out.println("setUsername: " + username);

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

}

And here's my faces-config:

<faces-config xmlns="http://java.sun.com/JSF/Configuration">

<managed-bean>

<managed-bean-name>EnqueteMBean</managed-bean-name>

<managed-bean-class>mct.data.mbeans.EnqueteMBean</managed-bean-class>

<managed-bean-scope>session</managed-bean-scope>

</managed-bean>

<navigation-rule>

<from-view-id>/index.jsp</from-view-id>

<navigation-case>

<from-action>#{EnqueteMBean.checkLogin}</from-action>

<from-outcome>loginCorrect</from-outcome>

<to-view-id>/admin.jsp</to-view-id>

</navigation-case>

</navigation-rule>

</faces-config>

I know it's a lot to look at but I'm really in the dark here and help would be appreciated very much!

Thanks allready

Greetz eLIX

[4795 byte] By [eLIXa] at [2007-11-27 10:26:06]
# 1

It seems that your error message doesn't match the JSP. The error message indicates that you were trying to access the username property on EnqueteMBean which does not exist. But in your JSP you have drilled into the newGebruiker property to get the username. Possibilities:

1) You are not running the code that is posted;

a) you posted the wrong code

b) failed to deploy the code or

c) perhaps the app server hasn't refreshed the JSP after deployment or

d) you are hitting a different page

2) The error message is misleading

3) My analysis is incorrect

RaymondDeCampoa at 2007-7-28 17:37:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hm, I'm definately running this code.

Because as you can see I've put different System.out.println("");'s in my code for testing.

And the strange thing is that he runs trough every class correctly.

Here are the println's I get when running it:

ENQUETEMBEAN

NEW GEBRUIKER

setUsername: peter

BEGIN CHECK LOGIN -

USERNAME: peter

PASSWORD: dob

END CHECK LOGIN -

ENQUETEDAO2

CONNECTIONMANAGER

CHECK USERNAME

CHECK USERNAME TRY

Database connection established

CHECK USERNAME TRY RESULTSET: com.mysql.jdbc.ResultSet@12be8e1

USERNAME peter EXISTS

-- BEGIN LOGIN --

username: peter

password: dob

-- END LOGIN --

So he does everything. He returns the string "loginCorrect" that is the "from-outcome" in the navigation-case.

eLIXa at 2007-7-28 17:37:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

O M G

I've just found the solution. I've never tought this would help.

I've just put 2 vars "username" and "password" in my EnqueteMBean with their getters and setters and it worked... Those vars with getters and setters have no use at all so I never tought it would work.

But thnx anyway for the help!

eLIXa at 2007-7-28 17:37:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...