// Check to see if the action bean already exists
ActionBean actionBean = (ActionBean) getPageContext().findAttribute(binding);
boolean beanNotPresent = actionBean == null;
try {
final Configuration config = StripesFilter.getConfiguration();
final ActionResolver resolver = StripesFilter.getConfiguration().getActionResolver();
final HttpServletRequest request = (HttpServletRequest) getPageContext().getRequest();
final HttpServletResponse response = (HttpServletResponse) getPageContext().getResponse();
Resolution resolution = null;
ExecutionContext ctx = new ExecutionContext();
// Lookup the ActionBean if we don't already have it
if (beanNotPresent) {
ActionBeanContext tempContext =
config.getActionBeanContextFactory().getContextInstance(request, response);
tempContext.setServletContext(getPageContext().getServletContext());
ctx.setLifecycleStage(LifecycleStage.ActionBeanResolution);
ctx.setActionBeanContext(tempContext);
// Run action bean resolution
ctx.setInterceptors(config.getInterceptors(LifecycleStage.ActionBeanResolution));
resolution = ctx.wrap( new Interceptor() {
public Resolution intercept(ExecutionContext ec) throws Exception {
ActionBean bean = resolver.getActionBean(ec.getActionBeanContext(), binding);
ec.setActionBean(bean);
return null;
}
});
}
else {
ctx.setActionBean(actionBean);
ctx.setActionBeanContext(actionBean.getContext());
}
// Then, if and only if an event was specified, run handler resolution
if (resolution == null && event != null && (beanNotPresent || this.alwaysExecuteEvent)) {
ctx.setLifecycleStage(LifecycleStage.HandlerResolution);
ctx.setInterceptors(config.getInterceptors(LifecycleStage.HandlerResolution));
resolution = ctx.wrap( new Interceptor() {
public Resolution intercept(ExecutionContext ec) throws Exception {
ec.setHandler(resolver.getHandler(ec.getActionBean().getClass(), event));
ec.getActionBeanContext().setEventName(event);
return null;
}
});
}
// Make the PageContext available during the validation stage so that we
// can execute EL based expression validation
try {
DispatcherHelper.setPageContext(getPageContext());
// Bind applicable request parameters to the ActionBean
if (resolution == null && (beanNotPresent || this.validate == true)) {
resolution = DispatcherHelper.doBindingAndValidation(ctx, this.validate);
}
// Run custom validations if we're validating
if (resolution == null && this.validate == true) {
String temp = config.getBootstrapPropertyResolver().getProperty(
DispatcherServlet.RUN_CUSTOM_VALIDATION_WHEN_ERRORS);
boolean validateWhenErrors = temp != null && Boolean.valueOf(temp);
resolution = DispatcherHelper.doCustomValidation(ctx, validateWhenErrors);
}