use of javax.enterprise.context.ContextNotActiveException 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 javax.enterprise.context.ContextNotActiveException in project deltaspike by apache.
the class ContainerCtrlTckTest method testRestartContexts.
/**
* Stops and starts: application-, session- and request-scope.
* <p/>
* application-scoped instance has a ref to
* request-scoped instance which has a ref to
* session-scoped instance.
* <p/>
* If the deepest ref has the expected value, all levels in between were resetted correctly.
*/
@Test
public void testRestartContexts() {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
Assert.assertNotNull(cdiContainer);
cdiContainer.boot();
cdiContainer.getContextControl().startContexts();
BeanManager beanManager = cdiContainer.getBeanManager();
Assert.assertNotNull(beanManager);
Set<Bean<?>> beans = beanManager.getBeans(CarRepair.class);
Bean<?> bean = beanManager.resolve(beans);
CarRepair carRepair = (CarRepair) beanManager.getReference(bean, CarRepair.class, beanManager.createCreationalContext(bean));
Assert.assertNotNull(carRepair);
Car car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
carRepair.getCar().getUser().setName("tester");
Assert.assertEquals("tester", car.getUser().getName());
Assert.assertFalse(CarRepair.isPreDestroyCalled());
Assert.assertFalse(Car.isPreDestroyCalled());
Assert.assertFalse(TestUser.isPreDestroyCalled());
cdiContainer.getContextControl().stopContexts();
Assert.assertTrue(CarRepair.isPreDestroyCalled());
Assert.assertTrue(Car.isPreDestroyCalled());
Assert.assertTrue(TestUser.isPreDestroyCalled());
try {
car.getUser();
// accessing the car should have triggered a ContextNotActiveException
Assert.fail();
} catch (ContextNotActiveException e) {
//do nothing - exception expected
}
cdiContainer.getContextControl().startContexts();
carRepair = (CarRepair) beanManager.getReference(bean, CarRepair.class, beanManager.createCreationalContext(bean));
Assert.assertNotNull(carRepair.getCar());
Assert.assertNotNull(carRepair.getCar().getUser());
Assert.assertNull(carRepair.getCar().getUser().getName());
cdiContainer.shutdown();
}
use of javax.enterprise.context.ContextNotActiveException in project deltaspike by apache.
the class ContainerCtrlTckTest method testNewRequests.
@Test
public void testNewRequests() {
CdiContainer cdiContainer = CdiContainerLoader.getCdiContainer();
Assert.assertNotNull(cdiContainer);
cdiContainer.boot();
cdiContainer.getContextControl().startContext(SessionScoped.class);
cdiContainer.getContextControl().startContext(RequestScoped.class);
BeanManager beanManager = cdiContainer.getBeanManager();
Assert.assertNotNull(beanManager);
TestUser testUser = resolveInstance(beanManager, TestUser.class);
Assert.assertNotNull(testUser);
testUser.setName("tester");
CarRepair carRepair = resolveInstance(beanManager, CarRepair.class);
Assert.assertNotNull(carRepair);
Car car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
Assert.assertEquals("tester", car.getUser().getName());
carRepair.getCar().getUser().setName("tck-tester");
Assert.assertEquals("tck-tester", testUser.getName());
cdiContainer.getContextControl().stopContext(RequestScoped.class);
cdiContainer.getContextControl().startContext(RequestScoped.class);
try {
testUser = resolveInstance(beanManager, TestUser.class);
Assert.assertNotNull(testUser);
Assert.assertNotNull(testUser.getName());
Assert.assertEquals("tck-tester", testUser.getName());
} catch (ContextNotActiveException e) {
Assert.fail(e.getMessage());
}
try {
carRepair = resolveInstance(beanManager, CarRepair.class);
Assert.assertNotNull(carRepair);
car = carRepair.getCar();
Assert.assertNotNull(car);
Assert.assertNotNull(car.getUser());
Assert.assertNotNull(car.getUser().getName());
Assert.assertEquals("tck-tester", car.getUser().getName());
} catch (ContextNotActiveException e) {
Assert.fail(e.getMessage());
}
cdiContainer.shutdown();
}
use of javax.enterprise.context.ContextNotActiveException in project deltaspike by apache.
the class JsfUtils method tryToRestoreMessages.
public static void tryToRestoreMessages(FacesContext facesContext) {
JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
if (!jsfModuleConfig.isAlwaysKeepMessages()) {
return;
}
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = windowMetaData.getFacesMessageEntryList();
List<FacesMessage> originalMessageList = new ArrayList<FacesMessage>(facesContext.getMessageList());
if (facesMessageEntryList != null) {
for (FacesMessageEntry messageEntry : facesMessageEntryList) {
if (isNewMessage(originalMessageList, messageEntry.getFacesMessage())) {
facesContext.addMessage(messageEntry.getComponentId(), messageEntry.getFacesMessage());
}
}
facesMessageEntryList.clear();
}
} catch (ContextNotActiveException e) {
//TODO discuss how we handle it
}
}
use of javax.enterprise.context.ContextNotActiveException in project deltaspike by apache.
the class JsfUtils method saveFacesMessages.
public static void saveFacesMessages(ExternalContext externalContext) {
JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
if (!jsfModuleConfig.isAlwaysKeepMessages()) {
return;
}
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
Map<String, Object> requestMap = externalContext.getRequestMap();
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = (List<FacesMessageEntry>) requestMap.get(FacesMessageEntry.class.getName());
if (facesMessageEntryList == null) {
facesMessageEntryList = new CopyOnWriteArrayList<FacesMessageEntry>();
}
windowMetaData.setFacesMessageEntryList(facesMessageEntryList);
} catch (ContextNotActiveException e) {
//TODO log it in case of project-stage development
//we can't handle it correctly -> delegate to the jsf-api (which has some restrictions esp. before v2.2)
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
}
}
Aggregations