use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor in project deltaspike by apache.
the class DeltaSpikePhaseListener method processInitView.
private void processInitView(String viewId) {
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
//view already initialized in this or any prev. request
if (viewId.equals(windowMetaData.getInitializedViewId())) {
return;
}
//override the view-id if we have a new view
windowMetaData.setInitializedViewId(viewId);
ViewConfigDescriptor viewDefinitionEntry = this.viewConfigResolver.getViewConfigDescriptor(viewId);
if (viewDefinitionEntry == null) {
return;
}
ViewControllerUtils.executeViewControllerCallback(viewDefinitionEntry, InitView.class);
} catch (ContextNotActiveException e) {
//TODO discuss how we handle it
}
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor 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 org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor in project deltaspike by apache.
the class ViewControllerActionListener method processAction.
@Override
public void processAction(ActionEvent actionEvent) {
if (this.activated) {
ViewConfigDescriptor viewConfigDescriptor = BeanProvider.getContextualReference(ViewConfigResolver.class).getViewConfigDescriptor(FacesContext.getCurrentInstance().getViewRoot().getViewId());
ViewControllerUtils.executeViewControllerCallback(viewConfigDescriptor, PreViewAction.class);
}
this.wrapped.processAction(actionEvent);
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor in project deltaspike by apache.
the class DeltaSpikeNavigationHandler method getNavigationCase.
@Override
public NavigationCase getNavigationCase(FacesContext context, String action, String outcome) {
if (this.wrapped instanceof ConfigurableNavigationHandler) {
if (!this.activated) {
return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
}
if (action == null && outcome != null && outcome.contains(".") && outcome.startsWith("class ") && !otherOutcomes.contains(outcome)) {
String originalOutcome = outcome;
NavigationCase navigationCase = this.viewConfigBasedNavigationCaseCache.get(originalOutcome);
if (navigationCase != null) {
return navigationCase;
}
outcome = outcome.substring(6);
ViewConfigDescriptor entry = null;
if (DefaultErrorView.class.getName().equals(originalOutcome)) {
ViewConfigResolver viewConfigResolver = JsfUtils.getViewConfigResolver();
entry = viewConfigResolver.getDefaultErrorViewConfigDescriptor();
}
if (entry == null) {
Object loadedClass = ClassUtils.tryToLoadClassForName(outcome);
if (loadedClass == null) {
this.otherOutcomes.add(originalOutcome);
} else if (ViewConfig.class.isAssignableFrom((Class) loadedClass)) {
entry = JsfUtils.getViewConfigResolver().getViewConfigDescriptor((Class<? extends ViewConfig>) loadedClass);
}
}
if (entry != null) {
View.NavigationMode navigationMode = entry.getMetaData(View.class).iterator().next().navigation();
navigationCase = new NavigationCase("*", null, null, null, entry.getViewId(), null, View.NavigationMode.REDIRECT.equals(navigationMode), false);
this.viewConfigBasedNavigationCaseCache.put(originalOutcome, navigationCase);
return navigationCase;
}
}
return ((ConfigurableNavigationHandler) this.wrapped).getNavigationCase(context, action, outcome);
}
return null;
}
use of org.apache.deltaspike.core.api.config.view.metadata.ViewConfigDescriptor in project deltaspike by apache.
the class ViewConfigTest method testSimpleViewConfigWithViewControllerCallback.
@Test
public void testSimpleViewConfigWithViewControllerCallback() {
this.viewConfigExtension.addPageDefinition(SimplePageConfig.class);
ViewConfigResolver viewConfigResolver = this.viewConfigResolverProducer.createViewConfigResolver();
ViewConfigDescriptor viewConfigDescriptor = viewConfigResolver.getViewConfigDescriptor(SimplePageConfig.class);
Assert.assertNotNull(viewConfigDescriptor);
Assert.assertNotNull(viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class));
Assert.assertEquals(PageBean001.class, viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().keySet().iterator().next());
Assert.assertEquals("preRenderViewCallbackMethod", ((List<Method>) viewConfigDescriptor.getCallbackDescriptor(ViewControllerRef.class, PreRenderView.class).getCallbackMethods().values().iterator().next()).iterator().next().getName());
}
Aggregations