[jboss-svn-commits] JBL Code SVN: r6209 - labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 13 15:38:02 EDT 2006


Author: unibrew
Date: 2006-09-13 15:38:01 -0400 (Wed, 13 Sep 2006)
New Revision: 6209

Modified:
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
Log:
[JBFORUMS-105] Parameters map in new portal is immutable. Parsing multipart requests had to be improved to work with immutable map - mainly a hack ;-).

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java	2006-09-13 19:15:08 UTC (rev 6208)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java	2006-09-13 19:38:01 UTC (rev 6209)
@@ -29,9 +29,15 @@
 import org.apache.myfaces.portlet.MyFacesGenericPortlet;
 
 import java.io.IOException;
+
+import java.lang.reflect.Field;
+
+import java.util.HashMap;
 import java.util.Iterator;
 
 //portlet api
+import java.util.Map;
+
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.RenderRequest;
@@ -40,14 +46,17 @@
 import javax.portlet.PortletSession;
 import javax.portlet.PortletMode;
 
-//jboss portal 
+//jboss portal
+import org.jboss.portal.portlet.Parameters;
+import org.jboss.portlet.JBossActionRequest;
+import org.jboss.portal.portlet.impl.jsr168.PortletRequestImpl;
 import org.jboss.portlet.forums.helper.TempFileBinding;
 import org.jboss.portlet.forums.ui.PortalUtil;
 
 
 /**
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
- *
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  * 
  */
 public class ForumsJSFPortlet extends MyFacesGenericPortlet 
@@ -220,6 +229,10 @@
      */
     private void processAttachments(ActionRequest req,ActionResponse response) throws Exception
     {
+        //We need to have new map to which we collect request parameters from multipart - we'll inject it little later
+        Map newParams = new HashMap();
+        newParams.putAll(req.getParameterMap());
+    
         DiskFileItemFactory factory = new DiskFileItemFactory();
         PortletFileUpload upload = new PortletFileUpload(factory);
         
@@ -231,7 +244,7 @@
            {
               //if it's form field just add it to request params map
               //TODO:Be aware that this adds single value as we won't have multiply values in new topic form for now...
-              req.getParameterMap().put(item.getFieldName(), new String[]{item.getString()});
+              newParams.put(item.getFieldName(), new String[]{item.getString()});
               
               //setup the render parameters properly to propagate to the JSF layer
               String parameter = item.getFieldName();
@@ -272,5 +285,30 @@
                PortalUtil.setUploadedAttachment(file);
            }
         } 
+        //we need to hack the request class and inject newly created Parameters map using reflection as this are
+        //protected fields
+        try
+        {
+           Class requestClass = PortletRequestImpl.class;
+           Field field = requestClass.getDeclaredField("parameters");
+           field.setAccessible(true);
+           field.set(req, new Parameters(newParams));
+
+
+           // TODO: This workaround is not best possible because we are using here JBossActionRequest.
+           //the second dummy field need to be set to null to force lazy initialization
+           requestClass = JBossActionRequest.class;
+           field = requestClass.getDeclaredField("blah");
+           field.setAccessible(true);
+           field.set(req, null);
+        }
+        catch (NoSuchFieldException e)
+        {
+           e.printStackTrace();
+        }
+        catch (IllegalAccessException e)
+        {
+           e.printStackTrace();
+        }
     }        
 }




More information about the jboss-svn-commits mailing list