myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wolfgang <wkl...@ebi.ac.uk>
Subject Re: Re: Re: [Tomahawk] NullPointer Exception during File-Upload
Date Thu, 06 Sep 2007 11:30:31 GMT
Hi sorry forgot to put the new html code inside.
Here it is:

      <h:form id="upload" enctype="multipart/form-data">

                            <t:inputFileUpload
                                    id="myUploadedFile"
                                    storage="file"
                                    accept="image/*"
                                    styleClass="myStyle"
                                    value="#{home.uploadFile}"/>

                            <h:commandButton 
actionListener="#{home.upload}"/>

                            </h:form>

> Hi Wolfgang,
>
> make sure that the surrounding h:form has enctype="multipart/form-data".
>
> cheers,
> christoph
>
> On 9/6/07, *Wolfgang* <wkluge@ebi.ac.uk <mailto:wkluge@ebi.ac.uk>> wrote:
>
>     Hi,
>
>     I tried to upload a File but I always got a NullPointerException,
>     because the uploadFile.getBytes(), uploadFile.getContentType() and
>     uploadFile.getName()) are null.
>
>     I don't understand why?!
>
>     Cheers!
>
>
>     private UploadedFile uploadFile;
>
>
>     public void upload(ActionEvent evt) throws IOException
>         {
>             FacesContext facesContext = FacesContext.getCurrentInstance();
>
>     facesContext.getExternalContext
>     ().getApplicationMap().put("fileupload_bytes",
>     uploadFile.getBytes());
>
>     facesContext.getExternalContext().getApplicationMap().put("fileupload_type",
>     uploadFile.getContentType());
>
>     facesContext.getExternalContext
>     ().getApplicationMap().put("fileupload_name",
>     uploadFile.getName());
>
>         }
>
>     // Getter and Setters
>
>         public UploadedFile getUploadFile() {
>             return uploadFile;
>         }
>
>         public void setUploadFile(UploadedFile uploadFile) {
>             this.uploadFile = uploadFile;
>         }
>
>
>     <t:inputFileUpload
>                                     id="myUploadedFile"
>                                     storage="file"
>                                     accept="image/*"
>                                     styleClass="myStyle"
>                                     value="#{home.uploadFile}"/>
>
>     <h:commandButton actionListener="#{home.upload}"/>
>
>


Mime
View raw message