[PJUG Javamail] problem getting JSF to work on NB 6.7.1 - PLEASE HELP
Michael Phoenix
michaelandrewphoenix at gmail.com
Tue Sep 15 19:26:13 EDT 2009
IJ'm going to bring my laptop to the meeting, this is really
frustraitng and it has me stumped. I'm not getting any kind of error
messages. It seems like JSF is just not finding the bean.
OK, I set up a JSF project on NB 6.7.1 and for some reason when I
click on the button to execute an action (loggedon.authenticate),
nothing happens except the form clears. I try to debug and it appears
that the method in the bean loggedon (LogonBean,java) is never even
entered. I've looked over the project and cannot figure out what is
going on. I really could use some help here. The important pieces of
code are below:
web.xml
[code]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
</web-app>
[/code]
faces-config.xml
[code]
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<managed-bean>
<managed-bean-name>loggedon</managed-bean-name>
<managed-bean-class>com.lingosys.quoteestimator.LogonBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/logon.jsp</from-view-id>
<navigation-case>
<from-outcome>loggedon</from-outcome>
<to-view-id>/request.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>returnce</from-outcome>
<to-view-id>/costestimator.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>returnjas</from-outcome>
<to-view-id>/jasgenerator.jsp</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
[/code]
logon.jsp
[code]
<%--
Document : logon
Created on : Sep 14, 2009, 3:31:40 PM
Author : mphoenix
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Quote Estimator Logon</title>
</head>
<body>
<f:view>
<h1>Quote Estimator Logon</h1>
<p/>
<h:form id="generateForm" enctype="multipart/form-data" >
<p/>Both fields are required.
<p/>Enter User ID: <h:inputText id="uid"
value="#{loggedon.uid}" required="true"/>
<p/>Enter Password: <h:inputSecret id="password"
required="true"
value="#{loggedon.password}"/>
<p/><h:commandButton value="Logon"
action="#{loggedon.authenticate}"/>
<p/><h:messages showDetail="true" showSummary="true"/>
</h:form>
</f:view>
</body>
</html>
[/code]
LogonBean.java
[code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.lingosys.quoteestimator;
import com.lingosys.hibernate.quoteest.User;
import com.lingosys.hibernate.quoteest.UserDao;
import com.lingosys.password.PasswordProcessor;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
/**
*
* @author mphoenix
*/
public class LogonBean {
private String uid = null;
private String password = null;
private boolean admin = false;
private boolean authenticated = false;
public LogonBean() {
}
public boolean getAuthenticated() {
return authenticated;
}
public void setAuthenticated(boolean authenticated) {
this.authenticated = authenticated;
}
public boolean getAdmin() {
return admin;
}
public void setAdmin(boolean admin) {
this.admin = admin;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String authenticate() throws NoSuchAlgorithmException,
NoSuchAlgorithmException, UnsupportedEncodingException {
UserDao dao = new UserDao();
User user = dao.find(getUid());
PasswordProcessor pp = PasswordProcessor.getInstance();
if (pp.encrypt(getPassword()).equals(user.getPassword())) {
setAuthenticated(true);
if (user.getAdmin() == 'Y')
setAdmin(true);
return "loggedon";
}
else {
FacesContext.getCurrentInstance().
addMessage(null, new FacesMessage("Incorrect user
ID and/or password, please try again."));
return "failed";
}
}
}
[/code]
More information about the Javamail
mailing list