use of javax.faces.context.ExternalContext in project joinfaces-bean-test by larmic.
the class FacesContextMock method replaceIn.
public FacesContextMock replaceIn(ApplicationContext applicationContext) {
final FacesContext facesContext;
final ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
if (!beanFactory.containsBean("facesContext")) {
facesContext = mock(FacesContext.class);
beanFactory.registerSingleton("facesContext", facesContext);
} else {
facesContext = (FacesContext) beanFactory.getBean("facesContext");
}
final ExternalContext externalContext = mock(ExternalContext.class);
final UIViewRoot uiViewRoot = mock(UIViewRoot.class);
when(facesContext.getExternalContext()).thenReturn(externalContext);
when(externalContext.getRequestParameterMap()).thenReturn(parameterMap);
when(facesContext.getViewRoot()).thenReturn(uiViewRoot);
when(uiViewRoot.getViewMap()).thenReturn(viewMap);
final Field field;
try {
field = FacesContext.class.getDeclaredField("instance");
field.setAccessible(true);
final ThreadLocal<FacesContext> threadLocal = (ThreadLocal<FacesContext>) field.get(null);
threadLocal.set(facesContext);
} catch (Exception e) {
throw new RuntimeException(e);
}
return this;
}
use of javax.faces.context.ExternalContext in project chuidiang-ejemplos by chuidiang.
the class UserLogin method validate.
public String validate() {
if ("juan".equals(userName) && "pedro".equals(password)) {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
session.setAttribute("userName", userName);
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
try {
context.redirect(context.getRequestContextPath() + "view.xhtml");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "view";
} else {
return "login";
}
}
use of javax.faces.context.ExternalContext in project opentheso by miledrousset.
the class NewTreeBean method getBrowserName.
/**
* Pour détecter les agents d'indexation
*
* @return
*/
public String getBrowserName() {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
String userAgent = externalContext.getRequestHeaderMap().get("User-Agent");
if (userAgent.toLowerCase().contains("slurp")) {
return "agent";
}
if (userAgent.toLowerCase().contains("msnbot")) {
return "agent";
}
if (userAgent.toLowerCase().contains("googlebot")) {
return "agent";
}
return "notagent";
}
use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.
the class GlobalExceptionHandler method handle.
public void handle() throws FacesException {
final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
while (i.hasNext()) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
final FacesContext fc = FacesContext.getCurrentInstance();
final ExternalContext externalContext = fc.getExternalContext();
try {
if (isSecurityException(t)) {
performRedirect(externalContext, "/login.htm");
} else if (isConversationException(t)) {
log.trace(t.getMessage(), t);
performRedirect(externalContext, "/conversation_error.htm");
}
if (isViewExpiredException(t)) {
storeRequestURI();
performRedirect(externalContext, "/login.htm");
} else {
log.trace(t.getMessage(), t);
performRedirect(externalContext, "/error.htm");
}
fc.renderResponse();
} finally {
i.remove();
}
}
getWrapped().handle();
}
use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.
the class GlobalExceptionHandler method storeRequestURI.
protected void storeRequestURI() {
ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
String requestUri = ((javax.servlet.http.HttpServletRequest) extContext.getRequest()).getRequestURI();
Identity identity = CdiUtil.bean(Identity.class);
identity.setSavedRequestUri(requestUri);
}
Aggregations