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.

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.

Customer surveys are for companies who didn't pay proper attention to begin with.

ian mcdavid
Greenhorn

Joined: Aug 24, 2010
Posts: 5

posted Aug 25, 2010 19:38:05

0

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?

"#{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).

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.