Adding File Upload to your projects
This step-by-step was created for developers in my organisation. Let me know if it needs changing.
!THERE IS NO NEED FOR A BACKING BEAN
Created a new EJB3 project (Called GUI)
Ran the seam gen to create a new project (./seam.sh new-project GUI)
Added the libraries commons-fileupload-1.1.jar, commons-io-1.2.jar, tomahawk.jar, commons-lang-2.1, commons-collections03.1,jar.jar to the lib folder
Refreshed the project in Eclipse
Added seam.jar, tomahawk.jar, myfaces-api-1.1.3.jar and sevlet-api.jar to the build path (not needed to easier to work with eclipse)
Changed myFacesLifeCycleBug to true in components.xml - may be the version I am using
Added the files jsf-comp.taglib.xml and tomahawk.taglib.xml to resources/web-inf directory
Added Extensions Filters to support tomahwk. These changes can be found under
<!-- My Faces Extensions Filter --> in web.xml
Referenced the tomahawk.taglib.xml resource in the web.xml file
(see under <!-- MyFaces Tomahawk Library --> in web.xml)
Created a MANIFEST.MF file to tell the archives where to find the jar files (in the ear of course)
Made the following changes to the build file to include the items required for tomahawk
Under build-jar where the jar file is created I added the manifest as below
<jar jarfile="${ear.dir}/GUI.jar" basedir="${classes.dir}" manifest="resources/META-INF/MANIFEST.MF">
Under build-ear under the fileset lib.dir needed to include jar files
(see <!--For Tomahawk--> in build.xml for build-ear)
Under build-ear I needed to include the manifest to where the ear gets created
<ear basedir="${ear.dir}" appxml="${ear.dir}/META-INF/application.xml" destfile="${dist.dir}/fileUploadGUI.ear" manifest="resources/META-INF/MANIFEST.MF"></ear>
Created class UploadSample (see code in sample zip)
Using the home.xhtml (because it is there)
add the namespace
mlns:t="http://myfaces.apache.org/tomahawk"
add
<t:inputFileUpload storage="file" value="#{upload.uploadFile}" styleClass="boxInput" id="fileUpload" ></t:inputFileUpload>
the value is the bijected field in UploadSample
The action is upload.upload. This is found in UploadSample
<h:commandButton value="Upload" action="#{upload.upload}"></h:commandButton>
And it needs to be wrapped in a h:form -- since I am using a button and submitting
<h:form enctype="multipart/form-data">
Build and Run.(I am in the all server)
The sample file can be downloaded from our site[base2Services.com downloads|http://www.base2services.com/downloads/gui.zip]
Comments