Author: dolander
Date: Wed Nov 17 07:10:37 2004
New Revision: 76140

Modified:
   
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
   
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
Log:
Bug fix in the Form.  There was an NPE if a form didn't contain any fields that 
have IDs.




Modified: 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
  (original)
+++ 
incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/IdMapper.java
  Wed Nov 17 07:10:37 2004
@@ -6,12 +6,20 @@
 import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 
+/**
+ * This class creates and process and ID to Expression map.  The map is used 
to store the mapping between
+ * the ID/Name elements in a form and the expression referencing the object 
the form element value maps to when
+ * the form is posted.  The basic reason for this mapping, is that expression 
may contain invalid characters for
+ * and NMTOKEN attribute.  In XHTML and HTML the id
+ */
 public class IdMapper
 {
-    private StringBuilder _idString;
+    // This is the character
     private static final String SPLIT = "\0";
     private static final String CHARSET = "ISO-8859-1";
 
+    private StringBuilder _idString;
+
     /**
      * Web.xml initialization parameter for attribute transparency
      */
@@ -30,16 +38,18 @@
         return _transparent.booleanValue();
     }
 
-    public static HashMap getExpressionMap(String expressions) {
+    public static HashMap getExpressionMap(String expressions)
+    {
         assert(expressions != null) : "Parameter 'expressions' must not be 
null";
 
         try {
-            String ex = new 
String(Base64.decode(expressions.getBytes(CHARSET)),CHARSET);
+            String ex = new 
String(Base64.decode(expressions.getBytes(CHARSET)), CHARSET);
             String[] expr = ex.split(SPLIT);
             assert((expr.length % 2) == 0) : "Verify that there is an even 
number of values failed";
             HashMap map = new HashMap(expr.length * 2 + 3);
-            for (int i=1;i<expr.length;i+=2) {
-                map.put(expr[i-1],expr[i]);
+            for (int i = 1; i < expr.length; i += 2) {
+                map.put(expr[i - 1], expr[i]);
+                System.err.println("Expand key '" + expr[i-1] + "' value '" + 
expr[i] + "'");
             }
             return map;
         }
@@ -66,7 +76,8 @@
         return id;
     }
 
-    public String getExpressions() {
+    public String getExpressions()
+    {
         String nameExpressions = _idString.toString();
         try {
             byte[] bytes = nameExpressions.getBytes(CHARSET);

Modified: 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
==============================================================================
--- 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    (original)
+++ 
incubator/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/html/Form.java
    Wed Nov 17 07:10:37 2004
@@ -34,7 +34,6 @@
 import org.apache.struts.config.FormBeanConfig;
 import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.taglib.html.Constants;
-import org.apache.xmlbeans.impl.util.Base64;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
@@ -44,7 +43,6 @@
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.PageContext;
 import java.util.*;
-import java.io.UnsupportedEncodingException;
 
 /**
  * This tag represents an input form, associated with a bean whose
@@ -737,7 +735,7 @@
             String token =
                     (String) 
session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
             if (token != null) {
-                writeHiddenParam(Constants.TOKEN_KEY, token, writer, request);
+                writeHiddenParam(Constants.TOKEN_KEY, token, writer, 
request,true);
             }
         }
         
@@ -751,12 +749,12 @@
                     String[] paramValArray = (String[]) paramValue;
                     for (int i = 0; i < paramValArray.length; i++) {
                         String paramName = 
URLRewriterService.rewriteName(servletContext, request, paramKey.toString());
-                        writeHiddenParam(paramName, paramValArray[i], writer, 
request);
+                        writeHiddenParam(paramName, paramValArray[i], writer, 
request,true);
                     }
                 }
                 else {
                     String paramName = 
URLRewriterService.rewriteName(servletContext, request, paramKey.toString());
-                    writeHiddenParam(paramName, paramValue.toString(), writer, 
request);
+                    writeHiddenParam(paramName, paramValue.toString(), writer, 
request,true);
                 }
             }
         }
@@ -765,7 +763,7 @@
         if (extraHiddenParams != null) {
             for (Iterator i = extraHiddenParams.entrySet().iterator(); 
i.hasNext();) {
                 Map.Entry entry = (Map.Entry) i.next();
-                writeHiddenParam((String) entry.getKey(), (String) 
entry.getValue(), writer, request);
+                writeHiddenParam((String) entry.getKey(), (String) 
entry.getValue(), writer, request,true);
             }
         }
 
@@ -779,9 +777,10 @@
         ImplicitObjectUtil.unloadActionForm(pageContext);
 
         // output the hidden fields for id transparency if this is turned on
-        if (IdMapper.isIdTransparency(servletContext)) {
+        if (IdMapper.isIdTransparency(servletContext) && _idMapper != null) {
             String encoded = _idMapper.getExpressions();
-            writeHiddenParam(ProcessPopulate.IDMAP_PARAMETER_NAME, encoded, 
writer, request);
+            writeHiddenParam(ProcessPopulate.IDMAP_PARAMETER_NAME, encoded, 
writer, request,false);
+            writer.append("\n");
         }
 
         // Render a tag representing the end of our current form
@@ -818,10 +817,11 @@
      * @param req        THe servlet request
      */
     private void writeHiddenParam(String paramName, String paramValue, 
AbstractRenderAppender results,
-                                  ServletRequest req)
+                                  ServletRequest req,boolean newLine)
     {
         // put each hidden on a new line
-        results.append("\n");
+        if (newLine)
+            results.append("\n");
 
         // create the state
         _hiddenState.clear();

Reply via email to