myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r694318 - in /myfaces/trinidad/branches/1.2.9.1-branch: trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/
Date Thu, 11 Sep 2008 15:53:34 GMT
Author: matzew
Date: Thu Sep 11 08:53:33 2008
New Revision: 694318

URL: http://svn.apache.org/viewvc?rev=694318&view=rev
Log:
TRINIDAD-1224 - Support converters for inputFile componet

The "problem" is, that getAsObject(....) only takes String, instead of Object.
Now, the SimpleInputFileRenderer uses a convention, to pass in a (unique) identifier. Before
that, the actual file is stored in the requestMap:
 =>externalContext.getRequestMap().put(someKeyForTheUploadedFile, theActualUploadedFileImplementation);

So... a custom converter would look for the key in the reqMap to do whatever "transformation"
is needed.

Modified:
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
    myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml?rev=694318&r1=694317&r2=694318&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
Thu Sep 11 08:53:33 2008
@@ -139,14 +139,29 @@
       <mfp:renderer-type>org.apache.myfaces.trinidad.File</mfp:renderer-type>
       <mfp:tag-name>tr:inputFile</mfp:tag-name>
       <mfp:tag-class>org.apache.myfaces.trinidadinternal.taglib.core.input.CoreInputFileTag</mfp:tag-class>
-      <mfp:long-description><![CDATA[The inputFile component is a component that
can
+      <mfp:long-description><![CDATA[<P>
+          The inputFile component is a component that can
           be used to upload a file.  Any Trinidad form that contains this component
           must have usesUpload set to true.  The &quot;value&quot; property
           of an inputFile component will be set to an instance
           of the <html:code>org.apache.myfaces.trinidad.model.UploadedFile</html:code>
           class when a file is uploaded (with the appropriate
           <html:code>ValueChangeEvent</html:code> delivered.)  Before
-          using this, developers must install the Apache Trinidad filter.]]>
+          using this, developers must install the Apache Trinidad filter.
+          </P>
+          <P>
+          The component supports custom converters to transform the <html:code>org.apache.myfaces.trinidad.model.UploadedFile</html:code>.
+          To archive this, the the <html:code>getAsObject()</html:code> method
is invoked, where the the <html:code>String</html:code> value
+          is a key, which must be used to query the actual uploaded file from the request
Map:
+          </p>
+          <pre>
+  public Object getAsObject(FacesContext context, UIComponent component, String fileKey)
+  {
+    UploadedFile file = (UploadedFile)context.getExternalContext().getRequestMap().get(fileKey);
+    // do transformation
+    return file;
+  }
+          </pre>]]>
       </mfp:long-description>
       <mfp:example>
         <mfp:source-code>

Modified: myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java?rev=694318&r1=694317&r2=694318&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
(original)
+++ myfaces/trinidad/branches/1.2.9.1-branch/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
Thu Sep 11 08:53:33 2008
@@ -22,6 +22,7 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
 
 import org.apache.myfaces.trinidad.bean.FacesBean;
@@ -103,7 +104,26 @@
       FacesMessage fm = MessageFactory.getMessage(context, "org.apache.myfaces.trinidad.UPLOAD");

       throw new ConverterException(fm);
     }
-    return submittedValue;
+
+    FacesBean bean = getFacesBean(component);
+    Converter converter = getConverter(bean);
+    // support converter for the <inputFile> component
+    if(converter != null)
+    {
+      // create a unique key (component class name + filename) and use this
+      // key to add the actual uploaded file to the requestMap
+      String fileNameKey = component.getClass().getName() + "." + file.getFilename();
+      context.getExternalContext().getRequestMap().put(fileNameKey, file);
+      
+      // applying the above convention. The String here is just the
+      // unique key which the converter has to use to look for the
+      // actual uploaded file.
+      return converter.getAsObject(context, component, fileNameKey);
+    }
+    else
+    {
+      return file;
+    }
   }
 
 



Mime
View raw message