我有一个PhaseListener并且不起作用。但是在我的同事的计算机上如果有效的话。
我使用netbeans 6.8 With Glassfish 2.1和Windows 32位
PhaseListener:
package mx.udg.cgti.seguridad.listener;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseListener;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import mx.udg.cgti.seguridadcore.negocio.ProcesosCNLocal;
public class SeguridadCorePhaseListener implements PhaseListener {
public SeguridadCorePhaseListener() {
}
public void beforePhase(PhaseEvent pe) {
System.out.println("beforePhase");
}
public void afterPhase(PhaseEvent pe) {
System.out.println("afterPhase");
if (pe.getPhaseId().equals(PhaseId.RESTORE_VIEW)) {
if (pe.getFacesContext() != null) {
String pagina = pe.getFacesContext().getViewRoot().getViewId();
if (!"/Inicio.xhtml".equalsIgnoreCase(pagina) && !"/Login.xhtml".equalsIgnoreCase(pagina) && pagina.contains(".xhtml")) {
loggedIn();
}
}
}
}
private void loggedIn() {
String pagina = "";
Long token = obtenToken();
if (token != null) {
String result = "";
result = lookupProcesosCNLocal().getSesionActiva(token);
if ("".equalsIgnoreCase(result)) {
result = null;
}
// System.out.println("RESULT " + result);
if (result == null) {
pagina = new String("sessionTimeout");
}
} else {
pagina = new String("sinSession");
}
// System.out.println(" PAGINA :- " + pagina + " TOKEN " + token);
if (!pagina.equalsIgnoreCase("")) {
// System.out.println("REGLAS DE NAVEGACION TRABAJANDO HACIA " + pagina);
FacesContext fc = FacesContext.getCurrentInstance();
NavigationHandler nh = fc.getApplication().getNavigationHandler();
nh.handleNavigation(fc, null, pagina);
fc.renderResponse();
}
}
private Long obtenToken() {
Long token = null;
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
Object t = request.getAttribute("token");
if (t == null) {
Object obj=null;
if(session != null){
obj = session.getAttribute("token");
if(obj == null){
obj = request.getParameter("token");
}
}else{
obj = request.getParameter("token");
}
if (obj != null) {
if (obj != null && !"".equalsIgnoreCase(obj.toString())) {
token = Long.parseLong(obj.toString());
}
}
} else {
token = Long.parseLong(t.toString());
}
if (token != null) {
request.setAttribute("token", token);
if(session == null){
session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
}
session.setAttribute("token", token);
}
return token;
}
public PhaseId getPhaseId() {
return PhaseId.RESTORE_VIEW;
}
private ProcesosCNLocal lookupProcesosCNLocal() {
try {
Context c = new InitialContext();
return (ProcesosCNLocal) c.lookup("java:comp/env/ProcesosCN");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
}
faces-config.xml中
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.0"
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_2_0.xsd">
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>logear</from-outcome>
<to-view-id>/Login.xhtml</to-view-id>
<redirect>1</redirect>
</navigation-case>
<navigation-case>
<from-outcome>sessionTimeout</from-outcome>
<to-view-id>/LoginError.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>sinSession</from-outcome>
<to-view-id>/LoginError.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<application>
<message-bundle>
mx.udg.cgti.seguridad.boundle.MiBoundle
</message-bundle>
</application>
<lifecycle>
<phase-listener>mx.udg.cgti.seguridad.listener.SeguridadCorePhaseListener</phase-listener>
</lifecycle>
<validator>
<validator-id>validaComboRequerido</validator-id>
<validator-class>mx.udg.cgti.seguridad.validator.ValidaComboRequerido</validator-class>
</validator>
<converter>
<converter-id>tipoUsuario</converter-id>
<converter-class>mx.udg.cgti.ln.convertidor.TipoUsuarioConverter</converter-class>
</converter>
<converter>
<converter-id>Usuario</converter-id>
<converter-class>mx.udg.cgti.ln.convertidor.UsuarioConverter</converter-class>
</converter>
<converter>
<converter-id>Rol</converter-id>
<converter-class>mx.udg.cgti.ln.convertidor.RolConverter</converter-class>
</converter>
<converter>
<converter-id>Permiso</converter-id>
<converter-class>mx.udg.cgti.ln.convertidor.PermisoConverter</converter-class>
</converter>
<converter>
<converter-id>UnidadOrganizacional</converter-id>
<converter-class>mx.udg.cgti.ln.convertidor.UnidadOrganizacionalConverter</converter-class>
</converter>
</faces-config>
答案 0 :(得分:0)
显然,你在类路径中的某个地方有另一个版本的同一个类,它在类加载到WAR中包含的类之前具有优先权。
可以位于服务器本身的/lib
文件夹内,也可以位于服务器使用的已安装JRE的/lib
或/lib/ext
文件夹中。