You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by we...@apache.org on 2006/12/29 23:03:05 UTC

svn commit: r491118 - /myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java

Author: weber
Date: Fri Dec 29 14:03:05 2006
New Revision: 491118

URL: http://svn.apache.org/viewvc?view=rev&rev=491118
Log:
TOBAGO-58 (Cleanup UIPage.processDecodes())

Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java?view=diff&rev=491118&r1=491117&r2=491118
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/component/UIPage.java Fri Dec 29 14:03:05 2006
@@ -121,89 +121,104 @@
   @Override
   public void processDecodes(FacesContext facesContext) {
 
-    // multipart/form-data must use TobagoMultipartFormdataRequest
-    String contentType = (String) facesContext.getExternalContext()
-        .getRequestHeaderMap().get("content-type");
-    if (contentType != null && contentType.startsWith("multipart/form-data")) {
-      Object request = facesContext.getExternalContext().getRequest();
-      boolean okay = false;
-      if (request instanceof TobagoMultipartFormdataRequest) {
-        okay = true;
-      } else if (request instanceof HttpServletRequestWrapper) {
-        ServletRequest wrappedRequest
-            = ((HttpServletRequestWrapper) request).getRequest();
-        if (wrappedRequest instanceof TobagoMultipartFormdataRequest) {
-          okay = true;
-        }
-      }
-      // TODO PortletRequest ??
-      if (!okay) {
-        LOG.error("Can't process multipart/form-data without TobagoRequest. "
-            + "Please check the web.xml and define a TobagoMultipartFormdataFilter. "
-            + "See documentation for <tc:file>");
-        facesContext.addMessage(null, new FacesMessage("An error has occured!"));
-      }
-    }
+    checkTobagoRequest(facesContext);
 
     decode(facesContext);
 
-    // reset old submitted state
-    setSubmitted(false);
+    clearScriptsAndPopups();
 
-    // clear script Set's
-    getOnloadScripts().clear();
-    getOnunloadScripts().clear();
-    getOnexitScripts().clear();
-    getScriptBlocks().clear();
-    getPopups().clear();
+    markSubmittedForm(facesContext);
 
+    // invoke processDecodes() on children
+    for (Iterator kids = getFacetsAndChildren(); kids.hasNext();) {
+      UIComponent kid = (UIComponent) kids.next();
+      kid.processDecodes(facesContext);
+    }
+  }
+
+  private void markSubmittedForm(FacesContext facesContext) {
     // find the form of the action command and set submitted to it and all
     // children
+
+    // reset old submitted state
+    setSubmitted(false);
+
     String currentActionId = getActionId();
     if (LOG.isDebugEnabled()) {
       LOG.debug("actionId = '" + currentActionId + "'");
     }
-    if (currentActionId == null) { // TODO: check why this is needed for dateControl
-      return;
-    }
 
     UIComponent command = null;
     try {
       command = findComponent(currentActionId);
-    } catch (IllegalArgumentException e) {
-      // FIXME: hotfix for TOBAGO-43
-    }
+    } catch (Exception e) {/* ignore */}
 
-    // FIXME: hotfix for UICommand inside of a sheet.
-    while (command == null && currentActionId.indexOf(':') != -1) {
-      currentActionId = StringUtils.substring(currentActionId, 0, currentActionId.lastIndexOf(':'));
-      command = findComponent(currentActionId);
+    if (command == null
+        && currentActionId != null && currentActionId.matches(".*:\\d+:.*")) {
+      // If currentActionId component was inside a sheet the id contains the
+      // rowindex and is therefore not found here.
+      // We do not need the row here because we want just to find the
+      // related form, so removing the rowindex will help here.
+      currentActionId = currentActionId.replaceAll(":\\d+:", ":");
+      try {
+        command = findComponent(currentActionId);
+      } catch (Exception e) {/* ignore */}
+    }
+
+    if (LOG.isTraceEnabled()) {
+      LOG.trace(currentActionId);
+      LOG.trace(command);
+      LOG.trace(ComponentUtil.toString(facesContext.getViewRoot(), 0));
     }
 
-    UIForm form = ComponentUtil.findForm(command);
+    if (command != null) {
+      UIForm form = ComponentUtil.findForm(command);
+      form.setSubmitted(true);
 
-    if (LOG.isDebugEnabled()) {
-      LOG.debug(command);
-      LOG.debug(form);
-      LOG.debug(ComponentUtil.toString(facesContext.getViewRoot(), 0));
-      if (form != null) {
-        LOG.debug(form.getClientId(facesContext));
+      if (LOG.isTraceEnabled()) {
+        LOG.trace(form);
+        LOG.trace(form.getClientId(facesContext));
       }
-    }
-
-    Iterator kids = getFacetsAndChildren();
-    while (kids.hasNext()) {
-      UIComponent kid = (UIComponent) kids.next();
-      kid.processDecodes(facesContext);
-    }
-
-    if (form != null) {
-      form.setSubmitted(true);
     } else {
       if (LOG.isDebugEnabled()) {
-        LOG.debug("No form found! Rerender the view.");
+        LOG.debug("Illegal actionId! Rerender the view.");
       }
       facesContext.renderResponse();
+    }
+  }
+
+  private void clearScriptsAndPopups() {
+    // clear script Set's
+    getOnloadScripts().clear();
+    getOnunloadScripts().clear();
+    getOnexitScripts().clear();
+    getScriptBlocks().clear();
+    getPopups().clear();
+  }
+
+  private void checkTobagoRequest(FacesContext facesContext) {
+    // multipart/form-data must use TobagoMultipartFormdataRequest
+    String contentType = (String) facesContext.getExternalContext()
+        .getRequestHeaderMap().get("content-type");
+    if (contentType != null && contentType.startsWith("multipart/form-data")) {
+      Object request = facesContext.getExternalContext().getRequest();
+      boolean okay = false;
+      if (request instanceof TobagoMultipartFormdataRequest) {
+        okay = true;
+      } else if (request instanceof HttpServletRequestWrapper) {
+        ServletRequest wrappedRequest
+            = ((HttpServletRequestWrapper) request).getRequest();
+        if (wrappedRequest instanceof TobagoMultipartFormdataRequest) {
+          okay = true;
+        }
+      }
+      // TODO PortletRequest ??
+      if (!okay) {
+        LOG.error("Can't process multipart/form-data without TobagoRequest. "
+            + "Please check the web.xml and define a TobagoMultipartFormdataFilter. "
+            + "See documentation for <tc:file>");
+        facesContext.addMessage(null, new FacesMessage("An error has occured!"));
+      }
     }
   }