use of javax.faces.component.UIViewRoot in project tutorials by eugenp.
the class PhaseListenerBean method beforeListener.
public void beforeListener(PhaseEvent event) {
if (!event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
return;
}
UIViewRoot root = event.getFacesContext().getViewRoot();
boolean showNewFeature = showNewFeatureForIp(event);
processComponentTree(root, event, showNewFeature);
}
use of javax.faces.component.UIViewRoot in project skeleton-commons by skeleton-software-community.
the class ViewScope method get.
/**
* {@inheritedDoc}
*/
@Override
public Object get(String name, ObjectFactory<?> objectFactory) {
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
if (viewRoot != null) {
Map<String, Object> viewMap = viewRoot.getViewMap();
if (viewMap.containsKey(name)) {
return viewMap.get(name);
} else {
Object object = objectFactory.getObject();
viewMap.put(name, object);
return object;
}
} else {
return null;
}
}
use of javax.faces.component.UIViewRoot in project deltaspike by apache.
the class SecurityAwareViewHandler method createView.
@Override
public UIViewRoot createView(FacesContext context, String viewId) {
UIViewRoot result = this.wrapped.createView(context, viewId);
if (!this.activated) {
return result;
}
if (this.securityModuleActivated == null) {
lazyInit();
}
if (!this.securityModuleActivated) {
return result;
}
UIViewRoot originalViewRoot = context.getViewRoot();
Map<String, Object> viewMap = null;
if (originalViewRoot != null) {
Map<String, Object> originalViewMap = originalViewRoot.getViewMap(false);
if (originalViewMap != null && !originalViewMap.isEmpty()) {
viewMap = new HashMap<String, Object>();
viewMap.putAll(originalViewMap);
}
}
// workaround for PreDestroyViewMapEvent which would be caused by the security check
deactivatePreDestroyViewMapEvent(context);
// we have to use it as current view if an AccessDecisionVoter uses the JSF API to check access to the view-id
context.setViewRoot(result);
try {
ViewRootAccessHandler viewRootAccessHandler = BeanProvider.getContextualReference(ViewRootAccessHandler.class);
viewRootAccessHandler.checkAccessTo(result);
} catch (ErrorViewAwareAccessDeniedException accessDeniedException) {
ViewConfigResolver viewConfigResolver = BeanProvider.getContextualReference(ViewConfigResolver.class);
ViewConfigDescriptor errorViewDescriptor = viewConfigResolver.getViewConfigDescriptor(accessDeniedException.getErrorView());
try {
if (errorViewDescriptor != null && View.NavigationMode.REDIRECT == errorViewDescriptor.getMetaData(View.class).iterator().next().navigation() && /*always available*/
BeanProvider.getContextualReference(JsfModuleConfig.class).isAlwaysUseNavigationHandlerOnSecurityViolation()) {
SecurityUtils.tryToHandleSecurityViolation(accessDeniedException);
} else {
SecurityUtils.handleSecurityViolationWithoutNavigation(accessDeniedException);
}
} finally {
broadcastAccessDeniedException(accessDeniedException);
}
if (errorViewDescriptor != null) {
return this.wrapped.createView(context, errorViewDescriptor.getViewId());
} else {
// the previous page (including the error message)
if (!context.isPostback() && context.getViewRoot() != null) {
context.getViewRoot().setViewId(null);
}
}
// security exception without error-view
throw accessDeniedException;
} finally {
activatePreDestroyViewMapEvent(context);
if (originalViewRoot != null) {
context.setViewRoot(originalViewRoot);
if (viewMap != null) {
originalViewRoot.getViewMap().putAll(viewMap);
}
}
}
return result;
}
use of javax.faces.component.UIViewRoot in project deltaspike by apache.
the class MockedJsfContainerTest method firstTest.
@Test
public void firstTest() {
Assert.assertEquals(0, requestScopedBean.getCount());
requestScopedBean.increaseCount();
Assert.assertEquals(1, requestScopedBean.getCount());
Assert.assertEquals(0, sessionScopedBean.getCount());
sessionScopedBean.increaseCount();
Assert.assertEquals(1, sessionScopedBean.getCount());
Assert.assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
Assert.assertEquals("/viewId", FacesContext.getCurrentInstance().getViewRoot().getViewId());
UIViewRoot uiViewRoot = new UIViewRoot();
uiViewRoot.setViewId("/test1.xhtml");
uiViewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
Assert.assertEquals("/test1.xhtml", FacesContext.getCurrentInstance().getViewRoot().getViewId());
Assert.assertNotNull(FacesContext.getCurrentInstance().getExternalContext());
Assert.assertNotNull(FacesContext.getCurrentInstance().getApplication());
Assert.assertNotNull(FacesContext.getCurrentInstance().getELContext());
Assert.assertNotNull(FacesContext.getCurrentInstance().getPartialViewContext());
Assert.assertNotNull(FacesContext.getCurrentInstance().getRenderKit());
Assert.assertNotNull(FacesContext.getCurrentInstance().getExceptionHandler());
Assert.assertNull(FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("test", "1");
Assert.assertEquals("1", FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
}
use of javax.faces.component.UIViewRoot in project deltaspike by apache.
the class MockedJsf2TestContainer method initDefaultView.
protected void initDefaultView() {
UIViewRoot root = new UIViewRoot();
root.setViewId("/viewId");
root.setLocale(getLocale());
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
this.facesContext.setViewRoot(root);
}
Aggregations