You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by jorge08 <jo...@gmail.com> on 2008/03/07 15:29:56 UTC

inputFileUpload issue when file does not exists

	
I am using the inputFileUpload Tomahawk component to upload files.
Everything works great except when the user types the file path and file
name directly into the input field. If the file path is wrong or the file
does not exists, there is no error messages displayed. I would like to
display a message to the user that the file does not exists. Is there a way
to validate if the file exists?

<h:form id="form1" enctype="multipart/form-data">
     <h:panelGrid columns="2" columnClasses="label,value" styleClass="form">
				
	<h:outputLabel value="* File:" for="fileupload"
styleClass="formLabel"></h:outputLabel>
		<h:panelGroup>
			<t:inputFileUpload id="fileupload"
	                               accept="image/*"
	                               value="#{fileBean.uploadedFile}"
	                               storage="file"
	                               styleClass="fileUploadInput"
	                               required="true"
	                               maxlength="180"></t:inputFileUpload>
	            	<h:message id="msgFile" for="fileupload" showDetail="true"
errorClass="errorMessage" infoClass="infoMessage" fatalClass="fatalMessage"
warnClass="warnMessage"/>
-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15892132.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Tinu V Thomas <ti...@gmail.com>.
Hi jorge,

Have you implemented the solution? 

thanks,
Tinu


jorge08 wrote:
> 
> Maybe it is a "feature" of IE, haha. Thanks a lot Martin, I will
> definitely implement it as suggested.
> Jorge
> 
> 
> Martin Marinschek wrote:
>> 
>> Hi jorge,
>> 
>> the HTML file-upload behaviour in IE is severely flawed. What you
>> could do is what Gmail is doing: just not display the file-entry-field
>> at all, display a link which allows the user to choose the file,
>> internally connect the link with the hidden file-input field via
>> JavaScript, then the interaction becomes a lot better...
>> 
>> regards,
>> 
>> Martin
>> 
>> On Wed, Mar 12, 2008 at 2:08 PM, jorge08 <jo...@gmail.com> wrote:
>>>
>>>  Actually, the behavior is different when I use FireFox. Silly me, I've
>>> only
>>>  been using IE to trace this issue. When I use FireFox and have an
>>> invalid
>>>  path or file name, the inputFileUpload field is bank out then I get
>>> "This
>>>  field is required" error since I require that field. Which is a much
>>> better
>>>  behavior that what I get using IE.
>>>  I did install the Live HTTP headers module in FireFox and I can see
>>> that the
>>>  filename field is indeed clear out before it is sent to the server. Is
>>> there
>>>  anything I can do for the IE users about this issue?
>>>  thanks,
>>>  Jorge
>>>
>>>
>>>
>>>  simon.kitching@chello.at wrote:
>>>  >
>>>  >
>>>
>>>
>>> > On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
>>>  >> Yes, but the problem is that my uploadAction method in my backing
>>> bean
>>>  >> does
>>>  >> NOT get executed when the file name is invalid or the file does not
>>>  >> exist.
>>>  >> Nothing happens when I click on the command button.
>>>  >
>>>  > Does the browser actually send anything back to the server in that
>>> case?
>>>  > If not, then there is nothing that can be done about that on the
>>> server
>>>  > end...
>>>  >
>>>  > For firefox, you can check this by installing the excellent
>>>  > "live-headers" addon, and seeing what data (if any) the browser sends
>>> to
>>>  > the server. Tracking that info down for other browser types is a
>>> little
>>>  > more difficult..
>>>  >
>>>  > Regards,
>>>  > Simon
>>>  >
>>>  >
>>>  >
>>>
>>>  --
>>>  View this message in context:
>>> http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p16002290.html
>>>
>>>
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
>> 
>> -- 
>> 
>> http://www.irian.at
>> 
>> Your JSF powerhouse -
>> JSF Consulting, Development and
>> Courses in English and German
>> 
>> Professional Support for Apache MyFaces
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p19490934.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by jorge08 <jo...@gmail.com>.
Maybe it is a "feature" of IE, haha. Thanks a lot Martin, I will definitely
implement it as suggested.
Jorge


Martin Marinschek wrote:
> 
> Hi jorge,
> 
> the HTML file-upload behaviour in IE is severely flawed. What you
> could do is what Gmail is doing: just not display the file-entry-field
> at all, display a link which allows the user to choose the file,
> internally connect the link with the hidden file-input field via
> JavaScript, then the interaction becomes a lot better...
> 
> regards,
> 
> Martin
> 
> On Wed, Mar 12, 2008 at 2:08 PM, jorge08 <jo...@gmail.com> wrote:
>>
>>  Actually, the behavior is different when I use FireFox. Silly me, I've
>> only
>>  been using IE to trace this issue. When I use FireFox and have an
>> invalid
>>  path or file name, the inputFileUpload field is bank out then I get
>> "This
>>  field is required" error since I require that field. Which is a much
>> better
>>  behavior that what I get using IE.
>>  I did install the Live HTTP headers module in FireFox and I can see that
>> the
>>  filename field is indeed clear out before it is sent to the server. Is
>> there
>>  anything I can do for the IE users about this issue?
>>  thanks,
>>  Jorge
>>
>>
>>
>>  simon.kitching@chello.at wrote:
>>  >
>>  >
>>
>>
>> > On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
>>  >> Yes, but the problem is that my uploadAction method in my backing
>> bean
>>  >> does
>>  >> NOT get executed when the file name is invalid or the file does not
>>  >> exist.
>>  >> Nothing happens when I click on the command button.
>>  >
>>  > Does the browser actually send anything back to the server in that
>> case?
>>  > If not, then there is nothing that can be done about that on the
>> server
>>  > end...
>>  >
>>  > For firefox, you can check this by installing the excellent
>>  > "live-headers" addon, and seeing what data (if any) the browser sends
>> to
>>  > the server. Tracking that info down for other browser types is a
>> little
>>  > more difficult..
>>  >
>>  > Regards,
>>  > Simon
>>  >
>>  >
>>  >
>>
>>  --
>>  View this message in context:
>> http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p16002290.html
>>
>>
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> 
> http://www.irian.at
> 
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p16048101.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Martin Marinschek <ma...@gmail.com>.
Hi jorge,

the HTML file-upload behaviour in IE is severely flawed. What you
could do is what Gmail is doing: just not display the file-entry-field
at all, display a link which allows the user to choose the file,
internally connect the link with the hidden file-input field via
JavaScript, then the interaction becomes a lot better...

regards,

Martin

On Wed, Mar 12, 2008 at 2:08 PM, jorge08 <jo...@gmail.com> wrote:
>
>  Actually, the behavior is different when I use FireFox. Silly me, I've only
>  been using IE to trace this issue. When I use FireFox and have an invalid
>  path or file name, the inputFileUpload field is bank out then I get "This
>  field is required" error since I require that field. Which is a much better
>  behavior that what I get using IE.
>  I did install the Live HTTP headers module in FireFox and I can see that the
>  filename field is indeed clear out before it is sent to the server. Is there
>  anything I can do for the IE users about this issue?
>  thanks,
>  Jorge
>
>
>
>  simon.kitching@chello.at wrote:
>  >
>  >
>
>
> > On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
>  >> Yes, but the problem is that my uploadAction method in my backing bean
>  >> does
>  >> NOT get executed when the file name is invalid or the file does not
>  >> exist.
>  >> Nothing happens when I click on the command button.
>  >
>  > Does the browser actually send anything back to the server in that case?
>  > If not, then there is nothing that can be done about that on the server
>  > end...
>  >
>  > For firefox, you can check this by installing the excellent
>  > "live-headers" addon, and seeing what data (if any) the browser sends to
>  > the server. Tracking that info down for other browser types is a little
>  > more difficult..
>  >
>  > Regards,
>  > Simon
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p16002290.html
>
>
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>



-- 

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: inputFileUpload issue when file does not exists

Posted by jorge08 <jo...@gmail.com>.
Actually, the behavior is different when I use FireFox. Silly me, I’ve only
been using IE to trace this issue. When I use FireFox and have an invalid
path or file name, the inputFileUpload field is bank out then I get “This
field is required” error since I require that field. Which is a much better
behavior that what I get using IE. 
I did install the Live HTTP headers module in FireFox and I can see that the
filename field is indeed clear out before it is sent to the server. Is there
anything I can do for the IE users about this issue?
thanks,
Jorge


simon.kitching@chello.at wrote:
> 
> 
> On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
>> Yes, but the problem is that my uploadAction method in my backing bean
>> does
>> NOT get executed when the file name is invalid or the file does not
>> exist.
>> Nothing happens when I click on the command button.
> 
> Does the browser actually send anything back to the server in that case?
> If not, then there is nothing that can be done about that on the server
> end...
> 
> For firefox, you can check this by installing the excellent
> "live-headers" addon, and seeing what data (if any) the browser sends to
> the server. Tracking that info down for other browser types is a little
> more difficult..
> 
> Regards,
> Simon
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p16002290.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Nitin Deshmukh <de...@yahoo.com>.
are you sure you don't any message in that case? do
you have a <h:messages /> in your page?
try to set showDetail="true" and showSummary="true"
for the h:messages and see if you get anything.


--- simon <si...@chello.at> wrote:

> 
> On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
> > Yes, but the problem is that my uploadAction
> method in my backing bean does
> > NOT get executed when the file name is invalid or
> the file does not exist.
> > Nothing happens when I click on the command
> button.
> 
> Does the browser actually send anything back to the
> server in that case?
> If not, then there is nothing that can be done about
> that on the server
> end...
> 
> For firefox, you can check this by installing the
> excellent
> "live-headers" addon, and seeing what data (if any)
> the browser sends to
> the server. Tracking that info down for other
> browser types is a little
> more difficult..
> 
> Regards,
> Simon
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


Re: inputFileUpload issue when file does not exists

Posted by simon <si...@chello.at>.
On Tue, 2008-03-11 at 12:01 -0700, jorge08 wrote:
> Yes, but the problem is that my uploadAction method in my backing bean does
> NOT get executed when the file name is invalid or the file does not exist.
> Nothing happens when I click on the command button.

Does the browser actually send anything back to the server in that case?
If not, then there is nothing that can be done about that on the server
end...

For firefox, you can check this by installing the excellent
"live-headers" addon, and seeing what data (if any) the browser sends to
the server. Tracking that info down for other browser types is a little
more difficult..

Regards,
Simon


Re: inputFileUpload issue when file does not exists

Posted by jorge08 <jo...@gmail.com>.
Yes, but the problem is that my uploadAction method in my backing bean does
NOT get executed when the file name is invalid or the file does not exist.
Nothing happens when I click on the command button.




Nitin Deshmukh wrote:
> 
> why don't you check if the file is null in the action
> method of the Bean. and if it is null or its size is
> zero, then add a Faces message for this component.
> 
> e.g.
> 
> in your jsp 
> 
> <t:inputFileUpload id="fileupload" accept="image/*"
> value="#{fileBean.uploadedFile}" storage="file"
> styleClass="fileUploadInput" required="true"
> maxlength="180"></t:inputFileUpload>
> 
> <h:message for="fileupload" />
> 
> <h:commandButton action="#{fileBean.uploadAction}" />
> 
> 
> Now in your fileBean, add the action method
> 
> public String uploadAction() {
>    if (uploadedFile == null || uploadedFile.getSize()
> == 0) {
>       
> FacesContext.getCurrentInstance().addMessage(="fileupload",
> new FacesMessage(FacesMessage.SEVERITY_ERROR, "File
> null", "Please specify a not null file."));
>     return null;
>    }
> }
> 
> I hope it helps.
> 
> 
> --- jorge08 <jo...@gmail.com> wrote:
> 
>> 
>> Matthias,
>> Thanks for your reply. The problem is that my
>> validator is not being
>> executed. By the way I am running myfaces 1.1.5. Has
>> anyone run into this
>> issue?
>> 
>> 
>> Matthias Wessendorf-4 wrote:
>> > 
>> > Hi,
>> > 
>> > I only know that Trinidad creates a 0 byte file,
>> when there is an
>> > "invalid" file,
>> > so a validator would work in Trinidad that way.
>> > 
>> > -M
>> > 
>> > On Mon, Mar 10, 2008 at 2:24 PM, jorge08
>> <jo...@gmail.com> wrote:
>> >>
>> >>  I've added a validator attribute to the
>> inputFileUpload component, but
>> >> it is
>> >>  not fired unless I have a valid file specified.
>> Here is what I have:
>> >>
>> >>                         <t:inputFileUpload
>> id="fileupload"
>> >>                                       
>> accept="image/*"
>> >>                                       
>> value="#{fileBean.uploadedFile}"
>> >>                                       
>> storage="file"
>> >>                                       
>> styleClass="fileUploadInput"
>> >>                                       
>> required="true"
>> >>
>> >>  validator="#{fileBean.validateFileExistance}"
>> >>                                       
>> >> maxlength="180"></t:inputFileUpload>
>> >>
>> >>  And in my backing bean I have:
>> >>  public void validateFileExistance(FacesContext
>> context, UIComponent
>> >>  toValidate,Object rcvRecord)throws Exception{
>> >>                 FacesMessage message = new
>> FacesMessage("Inside
>> >> validateFileExistance");
>> >>                 FacesContext facesContext =
>> >> FacesContext.getCurrentInstance();
>> >>                
>> >>
>>
> facesContext.addMessage(toValidate.getClientId(context),message);
>> >>                 ...
>> >>
>> >>         }
>> >>
>> >>  Any ideas?
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>  David Delbecq-2 wrote:
>> >>  >
>> >>  > You could add a custom validator that check
>> the length of the uploaded
>> >>  > file?
>> >>  > jorge08 a écrit :
>> >>  >>
>> >>  >> I am using the inputFileUpload Tomahawk
>> component to upload files.
>> >>  >> Everything works great except when the user
>> types the file path and
>> >> file
>> >>  >> name directly into the input field. If the
>> file path is wrong or the
>> >> file
>> >>  >> does not exists, there is no error messages
>> displayed. I would like
>> >> to
>> >>  >> display a message to the user that the file
>> does not exists. Is there
>> >> a
>> >>  >> way
>> >>  >> to validate if the file exists?
>> >>  >>
>> >>  >> <h:form id="form1"
>> enctype="multipart/form-data">
>> >>  >>      <h:panelGrid columns="2"
>> columnClasses="label,value"
>> >>  >> styleClass="form">
>> >>  >>
>> >>  >>      <h:outputLabel value="* File:"
>> for="fileupload"
>> >>  >> styleClass="formLabel"></h:outputLabel>
>> >>  >>              <h:panelGroup>
>> >>  >>                      <t:inputFileUpload
>> id="fileupload"
>> >>  >>                                    
>> accept="image/*"
>> >>  >>                                    
>> value="#{fileBean.uploadedFile}"
>> >>  >>                                    
>> storage="file"
>> >>  >>                                    
>> styleClass="fileUploadInput"
>> >>  >>                                    
>> required="true"
>> >>  >>                                    
>> >> maxlength="180"></t:inputFileUpload>
>> >>  >>                      <h:message id="msgFile"
>> for="fileupload"
>> >> showDetail="true"
>> >>  >> errorClass="errorMessage"
>> infoClass="infoMessage"
>> >>  >> fatalClass="fatalMessage"
>> >>  >> warnClass="warnMessage"/>
>> >>  >>
>> >>  >
>> >>  >
>> >>  >
>> >>
>> >>  --
>> >>  View this message in context:
>> >>
>>
> http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15950753.html
>> >>
>> >>
>> >> Sent from the MyFaces - Users mailing list
>> archive at Nabble.com.
>> >>
>> >>
>> > 
>> > 
>> > 
>> > -- 
>> > Matthias Wessendorf
>> > 
>> > further stuff:
>> > blog: http://matthiaswessendorf.wordpress.com/
>> > sessions: http://www.slideshare.net/mwessendorf
>> > mail: matzew-at-apache-dot-org
>> > 
>> > 
>> 
>> -- 
>> View this message in context:
>>
> http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15976473.html
>> Sent from the MyFaces - Users mailing list archive
>> at Nabble.com.
>> 
>> 
> 
> 
> 
>      
> ____________________________________________________________________________________
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile.  Try it now. 
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15985853.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Nitin Deshmukh <de...@yahoo.com>.
why don't you check if the file is null in the action
method of the Bean. and if it is null or its size is
zero, then add a Faces message for this component.

e.g.

in your jsp 

<t:inputFileUpload id="fileupload" accept="image/*"
value="#{fileBean.uploadedFile}" storage="file"
styleClass="fileUploadInput" required="true"
maxlength="180"></t:inputFileUpload>

<h:message for="fileupload" />

<h:commandButton action="#{fileBean.uploadAction}" />


Now in your fileBean, add the action method

public String uploadAction() {
   if (uploadedFile == null || uploadedFile.getSize()
== 0) {
      
FacesContext.getCurrentInstance().addMessage(="fileupload",
new FacesMessage(FacesMessage.SEVERITY_ERROR, "File
null", "Please specify a not null file."));
    return null;
   }
}

I hope it helps.


--- jorge08 <jo...@gmail.com> wrote:

> 
> Matthias,
> Thanks for your reply. The problem is that my
> validator is not being
> executed. By the way I am running myfaces 1.1.5. Has
> anyone run into this
> issue?
> 
> 
> Matthias Wessendorf-4 wrote:
> > 
> > Hi,
> > 
> > I only know that Trinidad creates a 0 byte file,
> when there is an
> > "invalid" file,
> > so a validator would work in Trinidad that way.
> > 
> > -M
> > 
> > On Mon, Mar 10, 2008 at 2:24 PM, jorge08
> <jo...@gmail.com> wrote:
> >>
> >>  I've added a validator attribute to the
> inputFileUpload component, but
> >> it is
> >>  not fired unless I have a valid file specified.
> Here is what I have:
> >>
> >>                         <t:inputFileUpload
> id="fileupload"
> >>                                       
> accept="image/*"
> >>                                       
> value="#{fileBean.uploadedFile}"
> >>                                       
> storage="file"
> >>                                       
> styleClass="fileUploadInput"
> >>                                       
> required="true"
> >>
> >>  validator="#{fileBean.validateFileExistance}"
> >>                                       
> >> maxlength="180"></t:inputFileUpload>
> >>
> >>  And in my backing bean I have:
> >>  public void validateFileExistance(FacesContext
> context, UIComponent
> >>  toValidate,Object rcvRecord)throws Exception{
> >>                 FacesMessage message = new
> FacesMessage("Inside
> >> validateFileExistance");
> >>                 FacesContext facesContext =
> >> FacesContext.getCurrentInstance();
> >>                
> >>
>
facesContext.addMessage(toValidate.getClientId(context),message);
> >>                 ...
> >>
> >>         }
> >>
> >>  Any ideas?
> >>
> >>
> >>
> >>
> >>
> >>
> >>  David Delbecq-2 wrote:
> >>  >
> >>  > You could add a custom validator that check
> the length of the uploaded
> >>  > file?
> >>  > jorge08 a écrit :
> >>  >>
> >>  >> I am using the inputFileUpload Tomahawk
> component to upload files.
> >>  >> Everything works great except when the user
> types the file path and
> >> file
> >>  >> name directly into the input field. If the
> file path is wrong or the
> >> file
> >>  >> does not exists, there is no error messages
> displayed. I would like
> >> to
> >>  >> display a message to the user that the file
> does not exists. Is there
> >> a
> >>  >> way
> >>  >> to validate if the file exists?
> >>  >>
> >>  >> <h:form id="form1"
> enctype="multipart/form-data">
> >>  >>      <h:panelGrid columns="2"
> columnClasses="label,value"
> >>  >> styleClass="form">
> >>  >>
> >>  >>      <h:outputLabel value="* File:"
> for="fileupload"
> >>  >> styleClass="formLabel"></h:outputLabel>
> >>  >>              <h:panelGroup>
> >>  >>                      <t:inputFileUpload
> id="fileupload"
> >>  >>                                    
> accept="image/*"
> >>  >>                                    
> value="#{fileBean.uploadedFile}"
> >>  >>                                    
> storage="file"
> >>  >>                                    
> styleClass="fileUploadInput"
> >>  >>                                    
> required="true"
> >>  >>                                    
> >> maxlength="180"></t:inputFileUpload>
> >>  >>                      <h:message id="msgFile"
> for="fileupload"
> >> showDetail="true"
> >>  >> errorClass="errorMessage"
> infoClass="infoMessage"
> >>  >> fatalClass="fatalMessage"
> >>  >> warnClass="warnMessage"/>
> >>  >>
> >>  >
> >>  >
> >>  >
> >>
> >>  --
> >>  View this message in context:
> >>
>
http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15950753.html
> >>
> >>
> >> Sent from the MyFaces - Users mailing list
> archive at Nabble.com.
> >>
> >>
> > 
> > 
> > 
> > -- 
> > Matthias Wessendorf
> > 
> > further stuff:
> > blog: http://matthiaswessendorf.wordpress.com/
> > sessions: http://www.slideshare.net/mwessendorf
> > mail: matzew-at-apache-dot-org
> > 
> > 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15976473.html
> Sent from the MyFaces - Users mailing list archive
> at Nabble.com.
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 


Re: inputFileUpload issue when file does not exists

Posted by jorge08 <jo...@gmail.com>.
Matthias,
Thanks for your reply. The problem is that my validator is not being
executed. By the way I am running myfaces 1.1.5. Has anyone run into this
issue?


Matthias Wessendorf-4 wrote:
> 
> Hi,
> 
> I only know that Trinidad creates a 0 byte file, when there is an
> "invalid" file,
> so a validator would work in Trinidad that way.
> 
> -M
> 
> On Mon, Mar 10, 2008 at 2:24 PM, jorge08 <jo...@gmail.com> wrote:
>>
>>  I've added a validator attribute to the inputFileUpload component, but
>> it is
>>  not fired unless I have a valid file specified. Here is what I have:
>>
>>                         <t:inputFileUpload id="fileupload"
>>                                        accept="image/*"
>>                                        value="#{fileBean.uploadedFile}"
>>                                        storage="file"
>>                                        styleClass="fileUploadInput"
>>                                        required="true"
>>
>>  validator="#{fileBean.validateFileExistance}"
>>                                       
>> maxlength="180"></t:inputFileUpload>
>>
>>  And in my backing bean I have:
>>  public void validateFileExistance(FacesContext context, UIComponent
>>  toValidate,Object rcvRecord)throws Exception{
>>                 FacesMessage message = new FacesMessage("Inside
>> validateFileExistance");
>>                 FacesContext facesContext =
>> FacesContext.getCurrentInstance();
>>                
>> facesContext.addMessage(toValidate.getClientId(context),message);
>>                 ...
>>
>>         }
>>
>>  Any ideas?
>>
>>
>>
>>
>>
>>
>>  David Delbecq-2 wrote:
>>  >
>>  > You could add a custom validator that check the length of the uploaded
>>  > file?
>>  > jorge08 a écrit :
>>  >>
>>  >> I am using the inputFileUpload Tomahawk component to upload files.
>>  >> Everything works great except when the user types the file path and
>> file
>>  >> name directly into the input field. If the file path is wrong or the
>> file
>>  >> does not exists, there is no error messages displayed. I would like
>> to
>>  >> display a message to the user that the file does not exists. Is there
>> a
>>  >> way
>>  >> to validate if the file exists?
>>  >>
>>  >> <h:form id="form1" enctype="multipart/form-data">
>>  >>      <h:panelGrid columns="2" columnClasses="label,value"
>>  >> styleClass="form">
>>  >>
>>  >>      <h:outputLabel value="* File:" for="fileupload"
>>  >> styleClass="formLabel"></h:outputLabel>
>>  >>              <h:panelGroup>
>>  >>                      <t:inputFileUpload id="fileupload"
>>  >>                                     accept="image/*"
>>  >>                                     value="#{fileBean.uploadedFile}"
>>  >>                                     storage="file"
>>  >>                                     styleClass="fileUploadInput"
>>  >>                                     required="true"
>>  >>                                    
>> maxlength="180"></t:inputFileUpload>
>>  >>                      <h:message id="msgFile" for="fileupload"
>> showDetail="true"
>>  >> errorClass="errorMessage" infoClass="infoMessage"
>>  >> fatalClass="fatalMessage"
>>  >> warnClass="warnMessage"/>
>>  >>
>>  >
>>  >
>>  >
>>
>>  --
>>  View this message in context:
>> http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15950753.html
>>
>>
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
> 
> 
> 
> -- 
> Matthias Wessendorf
> 
> further stuff:
> blog: http://matthiaswessendorf.wordpress.com/
> sessions: http://www.slideshare.net/mwessendorf
> mail: matzew-at-apache-dot-org
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15976473.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Matthias Wessendorf <ma...@apache.org>.
Hi,

I only know that Trinidad creates a 0 byte file, when there is an
"invalid" file,
so a validator would work in Trinidad that way.

-M

On Mon, Mar 10, 2008 at 2:24 PM, jorge08 <jo...@gmail.com> wrote:
>
>  I've added a validator attribute to the inputFileUpload component, but it is
>  not fired unless I have a valid file specified. Here is what I have:
>
>                         <t:inputFileUpload id="fileupload"
>                                        accept="image/*"
>                                        value="#{fileBean.uploadedFile}"
>                                        storage="file"
>                                        styleClass="fileUploadInput"
>                                        required="true"
>
>  validator="#{fileBean.validateFileExistance}"
>                                        maxlength="180"></t:inputFileUpload>
>
>  And in my backing bean I have:
>  public void validateFileExistance(FacesContext context, UIComponent
>  toValidate,Object rcvRecord)throws Exception{
>                 FacesMessage message = new FacesMessage("Inside validateFileExistance");
>                 FacesContext facesContext = FacesContext.getCurrentInstance();
>                 facesContext.addMessage(toValidate.getClientId(context),message);
>                 ...
>
>         }
>
>  Any ideas?
>
>
>
>
>
>
>  David Delbecq-2 wrote:
>  >
>  > You could add a custom validator that check the length of the uploaded
>  > file?
>  > jorge08 a écrit :
>  >>
>  >> I am using the inputFileUpload Tomahawk component to upload files.
>  >> Everything works great except when the user types the file path and file
>  >> name directly into the input field. If the file path is wrong or the file
>  >> does not exists, there is no error messages displayed. I would like to
>  >> display a message to the user that the file does not exists. Is there a
>  >> way
>  >> to validate if the file exists?
>  >>
>  >> <h:form id="form1" enctype="multipart/form-data">
>  >>      <h:panelGrid columns="2" columnClasses="label,value"
>  >> styleClass="form">
>  >>
>  >>      <h:outputLabel value="* File:" for="fileupload"
>  >> styleClass="formLabel"></h:outputLabel>
>  >>              <h:panelGroup>
>  >>                      <t:inputFileUpload id="fileupload"
>  >>                                     accept="image/*"
>  >>                                     value="#{fileBean.uploadedFile}"
>  >>                                     storage="file"
>  >>                                     styleClass="fileUploadInput"
>  >>                                     required="true"
>  >>                                     maxlength="180"></t:inputFileUpload>
>  >>                      <h:message id="msgFile" for="fileupload" showDetail="true"
>  >> errorClass="errorMessage" infoClass="infoMessage"
>  >> fatalClass="fatalMessage"
>  >> warnClass="warnMessage"/>
>  >>
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15950753.html
>
>
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>



-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
mail: matzew-at-apache-dot-org

Re: inputFileUpload issue when file does not exists

Posted by jorge08 <jo...@gmail.com>.
I've added a validator attribute to the inputFileUpload component, but it is
not fired unless I have a valid file specified. Here is what I have:
 			<t:inputFileUpload id="fileupload"
 	                               accept="image/*"
 	                               value="#{fileBean.uploadedFile}"
	                               storage="file"
 	                               styleClass="fileUploadInput"
 	                               required="true"
	                              
validator="#{fileBean.validateFileExistance}"
 	                               maxlength="180"></t:inputFileUpload>

And in my backing bean I have:
public void validateFileExistance(FacesContext context, UIComponent
toValidate,Object rcvRecord)throws Exception{
		FacesMessage message = new FacesMessage("Inside validateFileExistance");
		FacesContext facesContext = FacesContext.getCurrentInstance();
		facesContext.addMessage(toValidate.getClientId(context),message);
                ...

	}

Any ideas?




David Delbecq-2 wrote:
> 
> You could add a custom validator that check the length of the uploaded
> file?
> jorge08 a écrit :
>> 	
>> I am using the inputFileUpload Tomahawk component to upload files.
>> Everything works great except when the user types the file path and file
>> name directly into the input field. If the file path is wrong or the file
>> does not exists, there is no error messages displayed. I would like to
>> display a message to the user that the file does not exists. Is there a
>> way
>> to validate if the file exists?
>>
>> <h:form id="form1" enctype="multipart/form-data">
>>      <h:panelGrid columns="2" columnClasses="label,value"
>> styleClass="form">
>> 				
>> 	<h:outputLabel value="* File:" for="fileupload"
>> styleClass="formLabel"></h:outputLabel>
>> 		<h:panelGroup>
>> 			<t:inputFileUpload id="fileupload"
>> 	                               accept="image/*"
>> 	                               value="#{fileBean.uploadedFile}"
>> 	                               storage="file"
>> 	                               styleClass="fileUploadInput"
>> 	                               required="true"
>> 	                               maxlength="180"></t:inputFileUpload>
>> 	            	<h:message id="msgFile" for="fileupload" showDetail="true"
>> errorClass="errorMessage" infoClass="infoMessage"
>> fatalClass="fatalMessage"
>> warnClass="warnMessage"/>
>>   
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/inputFileUpload-issue-when-file-does-not-exists-tp15892132p15950753.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: inputFileUpload issue when file does not exists

Posted by Matthias Wessendorf <ma...@apache.org>.
Hi

On Sun, Mar 9, 2008 at 9:06 PM, david delbecq <de...@oma.be> wrote:
> You could add a custom validator that check the length of the uploaded file?

that can solve the issue, but only when you are not interested in
empty file (such as "flag files").

-M

>  jorge08 a écrit :
>
>
> >
>  > I am using the inputFileUpload Tomahawk component to upload files.
>  > Everything works great except when the user types the file path and file
>  > name directly into the input field. If the file path is wrong or the file
>  > does not exists, there is no error messages displayed. I would like to
>  > display a message to the user that the file does not exists. Is there a way
>  > to validate if the file exists?
>  >
>  > <h:form id="form1" enctype="multipart/form-data">
>  >      <h:panelGrid columns="2" columnClasses="label,value" styleClass="form">
>  >
>  >       <h:outputLabel value="* File:" for="fileupload"
>  > styleClass="formLabel"></h:outputLabel>
>  >               <h:panelGroup>
>  >                       <t:inputFileUpload id="fileupload"
>  >                                      accept="image/*"
>  >                                      value="#{fileBean.uploadedFile}"
>  >                                      storage="file"
>  >                                      styleClass="fileUploadInput"
>  >                                      required="true"
>  >                                      maxlength="180"></t:inputFileUpload>
>  >                       <h:message id="msgFile" for="fileupload" showDetail="true"
>  > errorClass="errorMessage" infoClass="infoMessage" fatalClass="fatalMessage"
>  > warnClass="warnMessage"/>
>  >
>
>



-- 
Matthias Wessendorf

further stuff:
blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
mail: matzew-at-apache-dot-org

Re: inputFileUpload issue when file does not exists

Posted by david delbecq <de...@oma.be>.
You could add a custom validator that check the length of the uploaded file?
jorge08 a écrit :
> 	
> I am using the inputFileUpload Tomahawk component to upload files.
> Everything works great except when the user types the file path and file
> name directly into the input field. If the file path is wrong or the file
> does not exists, there is no error messages displayed. I would like to
> display a message to the user that the file does not exists. Is there a way
> to validate if the file exists?
>
> <h:form id="form1" enctype="multipart/form-data">
>      <h:panelGrid columns="2" columnClasses="label,value" styleClass="form">
> 				
> 	<h:outputLabel value="* File:" for="fileupload"
> styleClass="formLabel"></h:outputLabel>
> 		<h:panelGroup>
> 			<t:inputFileUpload id="fileupload"
> 	                               accept="image/*"
> 	                               value="#{fileBean.uploadedFile}"
> 	                               storage="file"
> 	                               styleClass="fileUploadInput"
> 	                               required="true"
> 	                               maxlength="180"></t:inputFileUpload>
> 	            	<h:message id="msgFile" for="fileupload" showDetail="true"
> errorClass="errorMessage" infoClass="infoMessage" fatalClass="fatalMessage"
> warnClass="warnMessage"/>
>