Question & Answer
Question
How do you use the JavaServer Faces (JSF) component hx:fileupload to upload a file with Enterprise Generation Language (EGL) and IBM Rational Business Developer v8.0.1?
Cause
When using the hx:fileupload component with EGL, a question is how to map the actual value to an EGL data type.
Answer
All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. |
---|
A possible solution is to use the string type.
To store the content of the uploaded file, JSF will encode it with a Base64 encoding.
It is possible to decode it using the com.ibm.faces.util.Base64 class and the EGL ExternalType, for example:
|
- The EGL type could be something like:
|
- And the EGL page handler like:
|
- And finally the JSF page:
|
Note on how to limit the size of the upload:
The upload size can be limited at the JSF level by parameter com.ibm.faces.MAX_REQUEST_CONTENT_SIZE in web.xml.
This parameter will not prevent the application server from uploading the complete file before pssaing it the its Web container and finally JSF. This means for example that a file of 1Gb will be uploaded completely before being rejected by JSF so it can possibly cause OutOfMemory exceptions.
Another possibility is then to limit the size at the application server level. See the link in the below section on how to do it with Websphere Application Server:
- either using PostSizeLimit
or - HTTP request chunking
To test the attached project:
- Import it into RBD 8.0.1 using
File > Import > General > Existing Projects into Workspace
and then select from archive file
- Add the missing jar files under
WEB-INF\lib: fda7.jar, jsf-ibm.jar, odc-jsf.jar and rte.jar
which has been removed to reduce the size of the zip file (they can be copied over from a new EGL JSF Web project).
- Create the missing JavaSource folders using menu
File > New > Folder
- Publish it on a WebSphere Application Server 7.0
- On the project Explorer, right-click on page WebContent/MyUploadPage.jsp and select Run As..Run on Server
Related Information
Was this topic helpful?
Document Information
Modified date:
02 August 2018
UID
swg21318912