This discussion is archived
1 Reply Latest reply: Dec 7, 2012 7:09 AM by 896726 RSS

Declarative Component : UploadedFile Isssue for multiple file Upload case.

896726 Explorer
Currently Being Moderated
I have made one declarative component for the multiple file upload case; where i have add button that dynamically adds af:inputFile component to the popup dialog and similarly delete button to dynamically delete the selected inputFile component. Everything work fine such as:

1. add button adds the inputfile component properly and delete does the same.
2. upload of Multiple files also works fine. ( I keep the uploadedFile in the java.util.Map which is the pageFlowScope and once, Dialog box ok/cancel is clicked, i clear everything back).

User hit 5 times add button if they want to upload 5 images. and do upload for all the 5 inputFile components . (Add or Delete button should not be clicked after any upload , but before you can.)..


1. user uploaded; say 2 images but not yet clicked in the ok/cancel button yet... they are still in the upload dialog ..and hit ADD button again.
2. After that user uploads say another file/image and now UploadedFile's getInputStream() returns null, length becomes 0 for all the other uploadedFile except this newly uploaded file.

Now, here is the thing, i wrote my own customUplodedFile class which is just a wrapper and it return getInputStream() from this class and length from this class and it is working.... But i am not sure why does the uploadedFile loses it's value...
import org.apache.myfaces.trinidad.model.UploadedFile;

public interface ICustomUploadedFile
  extends Serializable, UploadedFile
  public String getFilename();

  public String getContentType();

  public long getLength();

  public Object getOpaqueData();

  public InputStream getInputStream();

  public void dispose();


public class CustomUploadedFile
  implements ICustomUploadedFile, Serializable
  private transient UploadedFile mUploadedFile;
  private transient InputStream mInputStream;
  private long mLength;

  public CustomUploadedFile()

  public CustomUploadedFile(UploadedFile pUploadedFile)
    this.mUploadedFile = pUploadedFile;
    this.mLength = pUploadedFile.getLength();
      this.mInputStream = pUploadedFile.getInputStream();
    catch (IOException e)


  public String getFilename()
    return mUploadedFile.getFilename();

  public String getContentType()
    return mUploadedFile.getContentType();

  public long getLength()
    return mLength;

  public Object getOpaqueData()
    return mUploadedFile.getOpaqueData();

  public InputStream getInputStream()
    return mInputStream;

  public void dispose()
Now, my questions are:

1. Is there a way i could follow to not to lose the UploadedFiles's inputStream and length by not using my wrapper class but in a standard way/best way.
2. I am not happy although it works because it is not making sense to me at all.....Why does the wrapper working though when i have transient variables; like UploadedFiles... and it's transient variables are lost why not mine.

I am totally confused at this stage.. Need your help.



  • Correct Answers - 10 points
  • Helpful Answers - 5 points