You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2008/09/11 17:49:56 UTC
svn commit: r694314 - in /myfaces/trinidad/trunk:
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/
Author: matzew
Date: Thu Sep 11 08:49:53 2008
New Revision: 694314
URL: http://svn.apache.org/viewvc?rev=694314&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/trunk/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
Modified: myfaces/trinidad/trunk/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml?rev=694314&r1=694313&r2=694314&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml (original)
+++ myfaces/trinidad/trunk/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreInputFile.xml Thu Sep 11 08:49:53 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 "value" 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/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java?rev=694314&r1=694313&r2=694314&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/SimpleInputFileRenderer.java Thu Sep 11 08:49:53 2008
@@ -21,6 +21,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;
@@ -101,7 +102,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;
+ }
}