• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

newbie null reference exception

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
faces configuration:

web.xml file:

Login.jsp/jsf whatever:

Login class definition:

error:

javax.faces.FacesException: #{Login.ValidateLogin}: java.lang.NullPointerException

I am a Java web development scrub / newbie. I am assuming this is because i did not have an instance of the Login class. However, tutorials that i have seen have done similar tasks without creating an instance (and they are not static classes) so i am confused. Please help me understand why i am getting this error and how to make this simple web application work. Thanks in advance.
 
Saloon Keeper
Posts: 28482
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Ian!

We have a "code" button in the message editor. I've used it to make your samples more readable.

Standard disclaimer: I don't care how many code examples start off with a login example, user-designed security systems are a menace to the Internet.

Standards notes: You shouldn't start package names with a capital letter. That's against the language conventions, even though it's technically legal. IDEs will yell at you. More specifically, class names should start with a capital letter. Most other things shouldn't. It provides a visual distinction between what is a class and what is an object, method or property. It also works better with tools that expect you to be conforming to standards. This also applies to bean names, by the way.

You did not initialize the username and password properties and you did not mark their corresponding View components with the "required" attribute. That means that it's possible to submit a form with null username and/or password and that will throw a NullPointerException.
 
ian mcdavid
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help so far. Another problem with this is that the fields are never getting set through the form. The navigation works and the validation function gets called, but the username and password fields are never getting set. Something behavior that deviates from the tutorials that i have seen is that the textInput components literally have the string #{Login.username} and #{Login.password} in them. Any ideas on how to make this work properly?
 
Tim Holloway
Saloon Keeper
Posts: 28482
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"#{Login.username}" isn't really a String, it's an EL Expression. That means that the framework is going to compile that expression to produce get/set property calls.

I don't see anything wrong with your field definitions, even though "Login" as a bean name is (as mentioned) not recommended capitalization (and interferes witjh your ability to use annotations in JSF2).

It's always a good idea to put a <h:messages/> element on the page, though. If you're having a problem that results in an error message, that element will display the message(s).
 
Tim Holloway
Saloon Keeper
Posts: 28482
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry. I misread. Again.

If your EL is being displayed instead of compiled, one of 2 things is probably to blame.

1. You're referencing the page via its resource path (.jsp) instead of its URL (.jsf). If you don't use the .jsf extension, then the request won't be processed by the FacesServlet and none of the JSF functions will work right.

2. You're missing TLD info that defines the "h" (and maybe "f") tag namespaces. I normally use xhtml (Facelets) with xml fomat, so I have supply the namespace info as part of my XML. If you're using JSP resources, check the book. There should be some additional text that goes above what you've shown, although for brevity's sake, they may omit it in the examples after the first 1 or 2.
 
Do you want ants? Because that's how you get ants. And a tiny ads:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic