You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by pb...@apache.org on 2007/07/29 20:29:46 UTC
svn commit: r560777 - in
/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands:
AbstractPopulateActionForm.java servlet/PopulateActionForm.java
Author: pbenedict
Date: Sun Jul 29 11:29:45 2007
New Revision: 560777
URL: http://svn.apache.org/viewvc?view=rev&rev=560777
Log:
STR-286 and STR-1116: Push isPopulate and isReset to superclass
Modified:
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractPopulateActionForm.java
struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/PopulateActionForm.java
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractPopulateActionForm.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractPopulateActionForm.java?view=diff&rev=560777&r1=560776&r2=560777
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractPopulateActionForm.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/AbstractPopulateActionForm.java Sun Jul 29 11:29:45 2007
@@ -20,6 +20,8 @@
*/
package org.apache.struts.chain.commands;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.chain.contexts.ActionContext;
@@ -34,6 +36,9 @@
* $
*/
public abstract class AbstractPopulateActionForm extends ActionCommandBase {
+
+ private static final Log log = LogFactory.getLog(AbstractPopulateActionForm.class);
+
// ---------------------------------------------------------- Public Methods
/**
@@ -57,14 +62,49 @@
return (false);
}
- // Reset and repopulate the form bean property values
- reset(actionCtx, actionConfig, actionForm);
- populate(actionCtx, actionConfig, actionForm);
+ // Reset the form bean only if configured so
+ if (isReset(actionCtx, actionConfig)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Reseting form bean '" + actionConfig.getName() + "'");
+ }
+ reset(actionCtx, actionConfig, actionForm);
+ }
+
+ // Populate the form bean only if configured so
+ if (isPopulate(actionCtx, actionConfig)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Populating form bean '" + actionConfig.getName() + "'");
+ }
+ populate(actionCtx, actionConfig, actionForm);
+ }
return (false);
}
// ------------------------------------------------------- Protected Methods
+
+ /**
+ * Determines whether an action form should be reset
+ *
+ * @param request current HTTP request
+ * @param actionConfig action config for current request
+ * @return true if action form should be reset
+ *
+ * @since Struts 1.4
+ */
+ protected abstract boolean isReset(ActionContext context,
+ ActionConfig actionConfig);
+
+ /**
+ * Determines whether an action form should be populated.
+ *
+ * @param context the ActionContext we are processing
+ * @param actionConfig action config for current request
+ * @return true if action form should be populated
+ * @since Struts 1.4
+ */
+ protected abstract boolean isPopulate(ActionContext context,
+ ActionConfig actionConfig);
/**
* <p>Call the <code>reset()</code> method on the specified form
Modified: struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/PopulateActionForm.java
URL: http://svn.apache.org/viewvc/struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/PopulateActionForm.java?view=diff&rev=560777&r1=560776&r2=560777
==============================================================================
--- struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/PopulateActionForm.java (original)
+++ struts/struts1/trunk/core/src/main/java/org/apache/struts/chain/commands/servlet/PopulateActionForm.java Sun Jul 29 11:29:45 2007
@@ -20,8 +20,6 @@
*/
package org.apache.struts.chain.commands.servlet;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
@@ -41,7 +39,6 @@
* $
*/
public class PopulateActionForm extends AbstractPopulateActionForm {
- private static final Log log = LogFactory.getLog(PopulateActionForm.class);
// ------------------------------------------------------- Protected Methods
@@ -51,23 +48,16 @@
ServletActionContext saContext = (ServletActionContext) context;
HttpServletRequest request = saContext.getRequest();
- // Populate the form bean only if configured so
- if (isPopulate(request, actionConfig)) {
- RequestUtils.populate(actionForm, actionConfig.getPrefix(),
- actionConfig.getSuffix(), saContext.getRequest());
- }
+ RequestUtils.populate(actionForm, actionConfig.getPrefix(),
+ actionConfig.getSuffix(), request);
}
protected void reset(ActionContext context, ActionConfig actionConfig,
ActionForm actionForm) {
-
ServletActionContext saContext = (ServletActionContext) context;
HttpServletRequest request = saContext.getRequest();
- // Reset the form bean only if configured so
- if (isReset(request, actionConfig)) {
- actionForm.reset((ActionMapping) actionConfig, saContext.getRequest());
- }
+ actionForm.reset((ActionMapping) actionConfig, request);
// Set the multipart class
if (actionConfig.getMultipartClass() != null) {
@@ -79,27 +69,33 @@
// ---------------------------------------------------------- Helper Methods
/**
- * Verifies whether an action form should be populated
+ * Determines whether an action form should be populated
* @param request current HTTP request
* @param actionConfig action config for current request
* @return true if action form should be populated
*
* @since Struts 1.4
*/
- protected boolean isPopulate(HttpServletRequest request, ActionConfig actionConfig) {
+ protected boolean isPopulate(ActionContext context, ActionConfig actionConfig) {
+ ServletActionContext saContext = (ServletActionContext) context;
+ HttpServletRequest request = saContext.getRequest();
+
String strPopulate = actionConfig.getPopulate();
return getResetOrPopulate(request, strPopulate);
}
/**
- * Verifies whether an action form should be reset
+ * Determines whether an action form should be reset
* @param request current HTTP request
* @param actionConfig action config for current request
* @return true if action form should be reset
*
* @since Struts 1.4
*/
- protected boolean isReset(HttpServletRequest request, ActionConfig actionConfig) {
+ protected boolean isReset(ActionContext context, ActionConfig actionConfig) {
+ ServletActionContext saContext = (ServletActionContext) context;
+ HttpServletRequest request = saContext.getRequest();
+
String strReset = actionConfig.getReset();
return getResetOrPopulate(request, strReset);
}
@@ -116,7 +112,7 @@
*
* @since Struts 1.4
*/
- protected boolean getResetOrPopulate(HttpServletRequest request, String strAttr) {
+ private boolean getResetOrPopulate(HttpServletRequest request, String strAttr) {
// Reset configuration is not defined (should not happen,
// because default value are set to "request,forward".
if (strAttr == null) return true;