/** * Creates new action request and initializes it. */ public ActionRequest( final MadvocController madvocController, final String actionPath, final String[] actionPathChunks, final ActionRuntime actionRuntime, final Object action, final HttpServletRequest servletRequest, final HttpServletResponse servletResponse) { this.madvocController = madvocController; this.actionPath = actionPath; this.actionPathChunks = actionPathChunks; this.actionRuntime = actionRuntime; this.servletRequest = servletRequest; this.servletResponse = servletResponse; this.action = action; this.targets = new Targets(this); this.executionIndex = 0; this.executionArray = createExecutionArray(); }
/** * Inject context into target. */ public void injectContext(final Object targetObject) { final Class targetType = targetObject.getClass(); final ScopeData scopeData = scopeDataInspector.inspectClassScopesWithCache(targetType); final Targets targets = new Targets(targetObject, scopeData); // inject no context scopeResolver.forEachScope(madvocScope -> madvocScope.inject(targets)); // inject special case scopeResolver.forScope(ParamsScope.class, scope -> scope.inject(targets)); // inject servlet context final ServletContext servletContext = madvocController.getApplicationContext(); if (servletContext != null) { scopeResolver.forEachScope(madvocScope -> madvocScope.inject(servletContext, targets)); } }
@Test void testInjection() { WebApp webapp = new WebApp(); webapp.start(); PetiteContainer madpc = webapp.madvocContainer().getPetiteContainer(); String baseName = StringUtil.uncapitalize(FooBean.class.getSimpleName()); madpc.defineParameter("foo", "1"); madpc.defineParameter(baseName + ".integer", "173"); madpc.defineParameter(baseName + ".string", "jodd"); madpc.defineParameter(baseName, "huh"); ParamsScope paramsScope = new ParamsScope(); BeanUtil.declared.setProperty(paramsScope, "madpc", madpc); FooBean fooBean = new FooBean(); paramsScope.inject(new Targets(fooBean, null)); assertEquals(173, fooBean.getInteger().intValue()); assertEquals("jodd", fooBean.getString()); } }