[cvs] expresso commit by rauld: fixed bug and improved getState()
method
JCorporate Ltd
jcorp at jcorporate.com
Sat Apr 9 14:38:30 UTC 2005
Log Message:
-----------
fixed bug and improved getState() method
Modified Files:
--------------
expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller:
DefaultForm.java
Revision Data
-------------
Index: DefaultForm.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/DefaultForm.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/DefaultForm.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/DefaultForm.java -u -r1.23 -r1.24
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/DefaultForm.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/DefaultForm.java
@@ -88,6 +88,7 @@
import java.util.Iterator;
import java.util.Locale;
import java.util.StringTokenizer;
+import com.jcorporate.expresso.core.misc.ConfigManager;
/**
@@ -260,125 +261,37 @@
/**
* Get the state requested by the transition button in the form
- *
- * @param request the servlet request we are processing
- *
+ * @param params the hashtable of parameters to parse
* @return String
* @throws ControllerException
+ *
+ * @author Raul Davidovich, improved by Nahuel
*/
- private static String getState(HttpServletRequest request) throws
- ControllerException {
+ protected String getState(HttpServletRequest request) throws ControllerException {
+
+ String state = request.getParameter("state");
- log.debug("Adding button parameters");
+ if (state == null) {
+ state = getField("state");
+ }
- String oneParamName = null;
+ if (state == null) {
+ // Transition to initial state
+ String controller = request.getParameter("controller");
- for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
- oneParamName = (String) e.nextElement();
-
- if (oneParamName.startsWith("button_")) {
-
- //We add a special parameter to the collection, which
- //is simply "button"="name_ofButton"
- String buttonName = oneParamName.substring(oneParamName.indexOf("_") + 1);
-
- /**
- * button names come in from the browser like
-
- button_promptLogin.y
- button_promptLogin.x
-
- cut off those .x, .y trailers
- */
- if (buttonName.endsWith(".x")) {
- buttonName = buttonName.substring(0, buttonName.length() - 2);
- }
- if (buttonName.endsWith(".y")) {
- buttonName = buttonName.substring(0, buttonName.length() - 2);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("There is a button parameter called '" +
- buttonName + "'");
- }
-
- /* pick up the corresponding parameter string, if any */
- String paramString = (String) request.getParameter(buttonName +
- "_params");
-
- if (paramString != null) {
- log.debug("Button parameters:");
-
- //We first check to see if the button parameters string is encoded. If it is, we decode it
- //before parsing it.
- String encodeType = (String) request.getParameter(buttonName +
- "_encoding");
-
- if ("u".equals(encodeType)) {
-
- //this param string has been URL encoded
- try {
- paramString = URLUTF8Encoder.decode(paramString);
- } catch (Exception ex) {
- log.error("Could not URLDecode: " + paramString,
- ex);
- }
- }
- /* if the param string for the button was encoded */
-
- /* parse it into a hashtable */
- StringTokenizer stkpm = null;
- stkpm = new StringTokenizer(paramString, "&");
-
- while (stkpm.hasMoreTokens()) {
- String pairValue = stkpm.nextToken();
-
- //This decode is paired up with the getParamString() method's encode() in
- //the Transition class.
- try {
- pairValue = URLUTF8Encoder.decode(pairValue);
- } catch (Exception ex) {
- log.error("Could not URLDecode: " + pairValue, ex);
- }
-
- String paramName = pairValue;
- String paramValue = "";
- int position = pairValue.indexOf("=");
- if (position != -1) {
- paramName = pairValue.substring(0, position);
- position++; //ignore the '='
- if (position < pairValue.length()) {
- paramValue = pairValue.substring(position);
- }
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Parameter '" + paramName + "', value '"
- + paramValue + "'");
- }
- if (paramName.equals(Controller.STATE_PARAM_KEY)) {
- return paramValue;
- }
-
- }
- /* while more parameters in the button param string */
-
- log.debug("End button parameters");
- } else { /* if the button param string exists */
- throw new ControllerException("Button '" + buttonName +
- "' was clicked, but no " +
- "button parameters field called '" +
- buttonName +
- "_params' was found.");
- }
+ if (controller == null) {
+ controller = getField("controller");
}
- /* if this param is a buitton */
+ if (controller != null) {
+ Controller ctrl = ConfigManager.getControllerFactory().getController(controller);
+ state = ctrl.getInitialState();
+ }
}
- /* for each of the parameters */
- return "";
- }
+ return (state == null)? "":state;
+
+ }
/**
* Initialize the <code>Validator</code> to perform validation.
More information about the cvs
mailing list