From b947948046d417e3a976c62ea2c0fb405c709e50 Mon Sep 17 00:00:00 2001 From: Diogo Neves Date: Wed, 13 Oct 2010 11:42:17 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@1533 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../src/java/global/Global.java | 80 ++++++++++++++----- 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/trunk/AnaliseAcidentesTrabalho/src/java/global/Global.java b/trunk/AnaliseAcidentesTrabalho/src/java/global/Global.java index 3193edce..058edda2 100755 --- a/trunk/AnaliseAcidentesTrabalho/src/java/global/Global.java +++ b/trunk/AnaliseAcidentesTrabalho/src/java/global/Global.java @@ -17,9 +17,11 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; +import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import utils.JSFUtils; /** @@ -143,27 +145,61 @@ public class Global { ctx.release(); } } - - public static void redirectToPlanos(FacesContext fc, Utilizador currentUser) - { - String curUser = "?user=" + currentUser.getId().toString(); - String estab = ""; - if(currentUser.getTipo().intValue() == Global.TIPO_UTILIZADOR_GESTOR) - { - //obtem estabelecimento da lista de estabelecimentos - estab = "&estab_gestor=" + currentUser.getEstabelecimento_gestor().intValue(); - } - fc = fc.getCurrentInstance(); - try - { - JSFUtils.redirect(fc, Global.PLANOS_ACTUACAO_URL + curUser + estab); - //JSFUtils.dispatch(fc, Global.PLANOS_ACTUACAO_URL + curUser); - } - catch(Exception ex) - { - ErrorLogger.logException( ex ); - } - - } + + + public static void redirectToPlanos( FacesContext fc, Utilizador currentUser ) + { + if ( fc != null ) + { +// String url = Global.PLANOS_ACTUACAO_URL; + String url = "http://localhost:8084/PlanosActuacao/faces/ListaPlanos.jsp"; + + ExternalContext ec = fc.getExternalContext(); + if ( ec != null ) + { + HttpSession session = ( HttpSession ) ec.getSession( false ); + if ( session != null ) + { + url += "?sessionID=" + session.getId(); + + int userType = currentUser == null ? -1 : currentUser.getTipo() == null ? -1 : currentUser.getTipo().intValue(); + if ( userType == Global.TIPO_UTILIZADOR_GESTOR ) + { + url += "&estab_gestor=" + currentUser.getEstabelecimento_gestor(); + } + + try + { + System.out.println( "\tRedirecting to : " + url ); + JSFUtils.redirect( fc, url ); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } + } + } + } + + +// public static void redirectToPlanos( FacesContext fc, Utilizador currentUser ) +// { +// String curUser = "?user=" + currentUser.getId().toString(); +// String estab = ""; +// if ( currentUser.getTipo().intValue() == Global.TIPO_UTILIZADOR_GESTOR ) +// { +// estab = "&estab_gestor=" + currentUser.getEstabelecimento_gestor().intValue(); +// } +// fc = fc.getCurrentInstance(); +// try +// { +// JSFUtils.redirect(fc, Global.PLANOS_ACTUACAO_URL + curUser + estab); +// } +// catch(Exception ex) +// { +// ErrorLogger.logException( ex ); +// } +// } }