This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsf exception

 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting this error trying to
bind a method to the action property of my component:

exception

javax.servlet.ServletException: #{customer.addNewUser}: javax.faces.el.MethodNotFoundException: addNewUser: com.corejsf.CustomerBean.addNewUser()
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)


root cause

javax.faces.FacesException: #{customer.addNewUser}: javax.faces.el.MethodNotFoundException: addNewUser: com.corejsf.CustomerBean.addNewUser()
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)


note The full stack trace of the root cause is available in the Tomcat logs.


and thsi is my component

<h:commandButton value="NewUser" action="#{customer.addNewUser}" />


so where is my error
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let us see how you defined the addNewUser method in com.corejsf.CustomerBean.

It should be a public no-argument method returning a java.lang.String. If it isn't the method signature won't match what the JSF framework is expecting.
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's my method
i'm still facing the same exception
public String addNewUser() throws SQLException, NamingException {
try {
open();

Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM USERS ");
//Name name=new Name("essam","ahmed");

return "AddSuccess";
} finally {
close();
}



}
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmmm. I'm not sure it's OK to list thrown exceptions. It seems unlikely, since the JSF framework isn't written to expect them. I think you're going to have to wrap your exceptions and rethrow them as JSF exceptions. JSF exceptions are unchecked exceptions, so you don't declare them in the method declaration.
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i removed all exeptions handling even i removed any code line form the method body amd i'm still stuck what should i do again


appreciate your help
 
Sushma Sharma
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can throw checked exceptions. It shouldn't matter. The problem is somewhere in your class declaration. How did you declare your managed bean and in which package is it?
 
Essam AbdelAziz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's my all bean



thank you very much
 
Sushma Sharma
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your class and the method look ok... the only thing left then is, check your classpath. looks like there is some other CustomerBean in your classpath and this one does not have addNewUser() method. Also check if you have the latest class in your tomcat webapps.
 
A. Dusi
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Everything looks okay except the throws part in your action method. Did you try removing it?
For exceptions in the action and actionListener methods, what I normally do is catch them, log them, add an appropriate FacesMessage to FacesContext so the users know about it and finally return ""(for action methods) or return(for actionListener methods).
Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic