Yes there is a contentType of file type not recognized by server. The
problem is, that InputFile doesn't return null if file doesn't exist. What
is more UploadFile dosen't have a method to check it. So I can even get
InputStream from UploadFile object with length = 0. There is no way to
differ an empty file from not existing file. So I wonder if it is a bug.

-----Original Message-----
From: Volker Weber [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 26, 2007 12:51 PM
To: MyFaces Discussion
Subject: Re: [Trinidad] How to check if file exists using InputFile
compon ent?


Hi,

is there a contentType if the file does not exists?


Regards,
    Volker

2007/7/26, Piotr Pikusa <[EMAIL PROTECTED]>:
> Thank you for reply. Unfortunately your method doesn't work with
> org.apache.myfaces.trinidad.model.UploadedFile object returned by
InputFile.
> UploadFile has a method getFilename() which returns name given by user. It
> still doesn't check if file exists, so it is not a name of real file. So
the
> problem still isn't solved.
>
> -----Original Message-----
> From: Volker Weber [mailto:[EMAIL PROTECTED]
> Sent: Thursday, July 26, 2007 11:40 AM
> To: MyFaces Discussion
> Subject: Re: [Trinidad] How to check if file exists using InputFile
> compon ent?
>
>
> Hi Piotr,
>
> i don't know the tomahawk InputFile component, but maybe you can check
> the uploaded filename?
>
> In tobago we check the filename to determine if a file was uploaded:
>
>  if (file == null || file.getName().length() == 0) {
>           addErrorMessage(facesContext);
>           setValid(false);
>  }
>
>
> Regards,
>     Volker
>
>
> 2007/7/26, Piotr Pikusa <[EMAIL PROTECTED]>:
> > In many toutorials about InputFile component (e.g on Oracle and Trinidad
> > sites) there is if instruction to check if uploadFile is not null. But
it
> > would never be null, event if the file doesn't exist. Is it a bug in
> > compoment? Is there any way to check file existence using InputFile
> > component?
> >
> >
> > -----Original Message-----
> > From: Piotr Pikusa [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, July 25, 2007 3:10 PM
> > To: 'MyFaces Discussion'
> > Subject: RE: [Trinidad] How to check if file exists using InputFile
compon
> > ent?
> >
> >
> > Unfotunately not. If the existing file is empty the getLength() method
> > returns 0 too. So the problem isn't still solved.
> >
> >
> > Matthias Wessendorf  wrote:
> >
> > hi piotr,
> >
> > the UploadedFile interfaces has a getLength() method
> >
> > it's 0, when the file isn't there..
> >
> > -M
> >
> > On 7/25/07, Piotr Pikusa <[EMAIL PROTECTED]> wrote:
> > > Hey!
> > >
> > > As it is mentioned in the subject I wonder if there is any possibility
> to
> > > check file existence.
> > > I got this code on my jsp page:
> > >
> > > [code]
> > >
> > > <tr:inputFile
> > >    required="true"
> > >    rendered="true"
> > >    label="Load File:"
> > >    value="#{backingBean.file}"
> > >  />
> > > <af:commandButton
> > >     text="#{"Button"}"
> > >     action="#{backingBean.importFile}" />
> > >
> > > [/code]
> > >
> > > which bind the value to the file property. The type of file is
> UploadFile.
> > > In backingBean I have this code:
> > >
> > > [code]
> > >
> > > UploadFile file;
> > >
> > > public void importFile(){
> > >         if(file != null) {
> > >                 doSomeAction();
> > >         }
> > >         else{
> > >                 returnError();
> > >         }
> > > }
> > >
> > > public UploadedFile getFile() {
> > >                 return file;
> > >         }
> > >
> > > public void setFile(UploadedFile file) {
> > >                 this.file = file;
> > > }
> > >
> > > [/code]
> > >
> > > The point of the problem is that the file is never null, no matter if
> file
> > > exists or not. If file doesn't exist the InputFile component doesn't
> > return
> > > null. The UploadFile doesn't have a method to check file existence.
> > > So my question is when file property can be null. And how to check if
> file
> > > exists using InputFile component and UploadFile object? (I cannot use
> > other
> > > type, but UploadFile).
> > >
> >
> >
> > --
> > Matthias Wessendorf
> >
> > further stuff:
> > blog: http://matthiaswessendorf.wordpress.com/
> > mail: matzew-at-apache-dot-org
> >
>

Reply via email to