use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.
the class AbstractExecuteAction method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Invoke the appropriate <code>Action</code> for this request, and
* cache the returned <code>ActionForward</code>.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Skip processing if the current request is not valid
Boolean valid = actionCtx.getFormValid();
if ((valid == null) || !valid.booleanValue()) {
return (false);
}
// Acquire the resources we will need to send to the Action
Action action = actionCtx.getAction();
if (action == null) {
return (false);
}
ActionConfig actionConfig = actionCtx.getActionConfig();
ActionForm actionForm = actionCtx.getActionForm();
// Execute the Action for this request, caching returned ActionForward
ForwardConfig forwardConfig = execute(actionCtx, action, actionConfig, actionForm);
actionCtx.setForwardConfig(forwardConfig);
return (false);
}
use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.
the class AbstractPopulateActionForm method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Populate the form bean (if any) for this request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception On an unexpected error
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Is there a form bean for this request?
ActionForm actionForm = actionCtx.getActionForm();
if (actionForm == null) {
return (false);
}
// Reset the form bean property values
ActionConfig actionConfig = actionCtx.getActionConfig();
reset(actionCtx, actionConfig, actionForm);
populate(actionCtx, actionConfig, actionForm);
handleCancel(actionCtx, actionConfig, actionForm);
return (false);
}
use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.
the class AbstractValidateActionForm method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Validate the properties of the form bean for this request. If there
* are any validation errors, execute the child commands in our chain;
* otherwise, proceed normally.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues, if there are
* no validation errors; otherwise <code>true</code>
* @throws Exception if thrown by the Action class
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Set form valid until found otherwise
actionCtx.setFormValid(Boolean.TRUE);
// Is there a form bean for this request?
ActionForm actionForm = actionCtx.getActionForm();
if (actionForm == null) {
return false;
}
// Is validation disabled on this request?
ActionConfig actionConfig = actionCtx.getActionConfig();
if (!actionConfig.getValidate()) {
return false;
}
// Was this request cancelled?
if (isCancelled(actionCtx, actionConfig)) {
if (LOG.isDebugEnabled()) {
LOG.debug(" Cancelled transaction, skipping validation");
}
return false;
}
// Call the validate() method of this form bean
ActionErrors errors = validate(actionCtx, actionConfig, actionForm);
// If there were no errors, proceed normally
if ((errors == null) || (errors.isEmpty())) {
return false;
}
// Flag the validation failure and proceed
/* NOTE: Is there any concern that there might have already
* been errors, or that other errors might be coming?
*/
actionCtx.saveErrors(errors);
actionCtx.setFormValid(Boolean.FALSE);
return false;
}
use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.
the class CreateActionForm method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Create (if necessary) and cache a form bean for this request.</p>
*
* @param actionCtx The <code>Context</code> for the current request
* @return <code>false</code> so that processing continues
* @throws Exception on any error
*/
public boolean execute(ActionContext actionCtx) throws Exception {
// Is there a form bean associated with this ActionConfig?
ActionConfig actionConfig = actionCtx.getActionConfig();
String name = actionConfig.getName();
if (name == null) {
actionCtx.setActionForm(null);
return (false);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Look up form-bean " + name);
}
// Look up the corresponding FormBeanConfig (if any)
FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name);
if (formBeanConfig == null) {
LOG.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix() + " under name " + name);
actionCtx.setActionForm(null);
return (false);
}
Map scope = actionCtx.getScope(actionConfig.getScope());
ActionForm instance;
instance = (ActionForm) scope.get(actionConfig.getAttribute());
// Can we recycle the existing instance (if any)?
if (!formBeanConfig.canReuse(instance)) {
instance = formBeanConfig.createActionForm(actionCtx);
}
// directly depends on ActionServlet
if (actionCtx instanceof ServletActionContext) {
// The servlet property of ActionForm is transient, so
// ActionForms which are restored from a serialized state
// need to have their servlet restored.
ServletActionContext sac = (ServletActionContext) actionCtx;
instance.setServlet(sac.getActionServlet());
}
actionCtx.setActionForm(instance);
scope.put(actionConfig.getAttribute(), instance);
return (false);
}
use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.
the class FormBeanConfig method createActionForm.
// --------------------------------------------------------- Public Methods
/**
* <p>Create and return an <code>ActionForm</code> instance appropriate to
* the information in this <code>FormBeanConfig</code>.</p>
*
* <p>Although this method is not formally deprecated yet, where possible,
* the form which accepts an <code>ActionContext</code> as an argument is
* preferred, to help sever direct dependencies on the Servlet API. As
* the ActionContext becomes more familiar in Struts, this method will
* almost certainly be deprecated.</p>
*
* @param servlet The action servlet
* @return ActionForm instance
* @throws IllegalAccessException if the Class or the appropriate
* constructor is not accessible
* @throws InstantiationException if this Class represents an abstract
* class, an array class, a primitive type,
* or void; or if instantiation fails for
* some other reason
*/
public ActionForm createActionForm(ActionServlet servlet) throws IllegalAccessException, InstantiationException {
Object obj = null;
// Create a new form bean instance
if (getDynamic()) {
obj = getDynaActionFormClass().newInstance();
} else {
obj = formBeanClass().newInstance();
}
ActionForm form = null;
if (obj instanceof ActionForm) {
form = (ActionForm) obj;
} else {
form = new BeanValidatorForm(obj);
}
form.setServlet(servlet);
if (form instanceof DynaBean && ((DynaBean) form).getDynaClass() instanceof MutableDynaClass) {
DynaBean dynaBean = (DynaBean) form;
MutableDynaClass dynaClass = (MutableDynaClass) dynaBean.getDynaClass();
// Add properties
dynaClass.setRestricted(false);
FormPropertyConfig[] props = findFormPropertyConfigs();
for (int i = 0; i < props.length; i++) {
dynaClass.add(props[i].getName(), props[i].getTypeClass());
dynaBean.set(props[i].getName(), props[i].initial());
}
dynaClass.setRestricted(isRestricted());
}
if (form instanceof BeanValidatorForm) {
((BeanValidatorForm) form).initialize(this);
}
return form;
}
Aggregations