Skip to Content
Author's profile photo George Ushakov

Upload file in VC with an EPCF event from a JspDynPage

In NetWeaver 7.0 there is no straight way available for uploading a file in Visual Composer. In this blog I’ll show how to overcome this limitation by using an HTML component with URL pointing to a JspDynPage using an HTMLB file upload tag, and generating an EPCF portal event to communicate the information about the uploaded file back to the iView controlled by VC.

Some information for this blog was taken from these useful links.

Here how the proof-of-concept iView may look like. On the left we have an HTML component with the URL to the JspDynPage. After the file is uploaded to some temporary folder on the AS. The information is sent via an EPCF client event to a simple table in the iView.

To implement this solution start by creating a simple PAR project with a JspDynPage. Here is the portalapp.xml file for this project. Notice the appropriate component-profile entry needed for the setup of the HTMLB tag library in your JSPs.

    <property name="PrivateSharingReference" value=""/>
    <component name="TmpFileUploadJspDynPage">
        <property name="ClassName" value=""/>
        Add this component profile property to be able to use htmlb taglib in the JSP
        <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>

Here is the code for the file_upload.jsp.

<%@ taglib uri="tagLib" prefix="hbj" %>
<hbj:content id="uploadContent" >
  <hbj:page title="File Upload">
   <hbj:form id="uploadForm" encodingType="multipart/form-data">
        <hbj:fileUpload id="fileUpload" maxLength="100000" size="30"/>
        <hbj:button id="submitButton" text="Upload" onClick="UploadFile" design="STANDARD"/>

And here is the corresponding Java class,

public class TmpFileUploadJspDynPage extends PageProcessorComponent {
    private static final Location logger =
    public DynPage getPage() {
        return new TmpFileUploadJspDynPageDynPage();
    public static class TmpFileUploadJspDynPageDynPage extends JSPDynPage {
        public void doInitialization() {
        public void doProcessAfterInput() throws PageException {
        public void doProcessBeforeOutput() throws PageException {
        public void onUploadFile(Event event) {
            logger.debugT("Processing UploadFile event");
            IPortalComponentRequest request =
                (IPortalComponentRequest) this.getRequest();
            IPortalComponentResponse response =
                (IPortalComponentResponse) this.getResponse();
            //get the file upload HTMLB component
            FileUpload fileUpload =
                (FileUpload) this.getPageContext().getComponentForId("fileUpload");
            logger.debugT("Got fileUpload component " + fileUpload);
            //check if there were a file uploaded
            if (fileUpload.getFile() != null) {
                String fileName = fileUpload.getFile().getFileName();
                String fileMimeType = fileUpload.getFile().getContentType();
                File tempFile = null;
                try {
                    tempFile = File.createTempFile("_upload_htmlb_", ".tmp");
                } catch (IOException e) {
                String filePath = tempFile.getAbsolutePath();
                logger.debugT("File name: " + fileName);
                logger.debugT("File mimetype: " + fileMimeType);
                logger.debugT("Temporary file location: " + filePath);
                //create a EPCF event with file info
                String jsCall =
                    "<script language='JavaScript'>"
                        + "alert('Raising {}evt1 event: fileName "
                        + fileName
                        + ", fileMimeType "
                        + fileMimeType
                        + ", filePath "
                        + filePath
                        + "');"
                        + "EPCM.raiseEvent('',"
                        + "'evt1',"
                        + "'<Params version=\"2\">"
                        + "<Row fileName=\""
                        + fileName
                        + "\" fileMimeType=\""
                        + fileMimeType
                        + "\" filePath=\""
                        + filePath
                        + "\"/>"               
                        + "</Params>',"
                        + "'/irj/servlet/prt/portal/prteventname/HtmlbEvent/prtroot/TmpFileUploadPar.TmpFileUploadJspDynPage');"
                        + "</script>";
                        logger.debugT("JavaScript call: " + jsCall);

We recuperate the uploaded file information from the fileUpload HTMLB component and use EPCM.raiseEvent() JavaScript call to fire a portal event with a specific namespace (, name (evt1, arbitrary but needs to be the same as configured in iView in VC, see below), and the event’s parameters in XML. Below is a template for EPCM event with parameters param1 and param2 and corresponding values val1 and val2. You can have more than one Row element.

<Params version="2">
<Row param1="val1" param2="val2"/>

Below is the model for the proof-of-concept iView in the VC. The iView registers an even handler for the portal {event}evt1 raised through the EPCF client API on the  JspDynPage and transfers the event’s parameters’ values in to a table  component.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.