1 2 Previous Next 15 Replies Latest reply on Jan 23, 2009 4:58 AM by Ronald van Kuijk

    Attaching files

    Varun Doda Newbie

      Hi,

      I want to create a form in which i have the option of attaching a file. For eg, there is a 'Browse' button which opens a pop up window to browse for a file. Then there is a upload button which will upload the file to the server. Is there any way to implement this?

        • 1. Re: Attaching files
          David Ling Newbie

          I actually did this a few days ago. The real difficulty I found was trying to include a

          <h:form enctype="multipart/form-data">...</h:form>
          inside the
          <jbpm:dataform>...</jbpm:dataform>
          . So I created an upload page, uploadFile.xhtml and placed it in the sa directory along with all the other .xhtml files.

          I then passed the parameters along in the url with
          <f:param name="" value=""/>


          So for example if I need to upload a document in one of the process task forms, I will put in the following
          <h:outputLink value="uploadFile.jsf" target="top" style="#{view.viewId == 'uploadFile.xhtml' ? 'font-weight:bold' : ''}">
          <f:param name="id" value="#{var['piID']}"/>
          <f:param name="ppFileName" value="Pretty print file name for display on the upload page"/>
          <f:param name="fileVar" value="processInstanceVariableToSaveUnder"/>
          <f:param name="fileName" value="The name that you want to save the file under"/>
          <h:outputText value="Click here to upload"/>
          </h:outputLink>
          


          The upload page looks like the following
          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          
          <html xmlns="http://www.w3.org/1999/xhtml"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:gd="http://gravel.jboss.org/jsf/1.0/data"
           xmlns:ga="http://gravel.jboss.org/jsf/1.0/action"
           xmlns:gs="http://gravel.jboss.org/jsf/1.0/simple"
           xmlns:n="http://gravel.jboss.org/jsf/1.0/navigation"
           xmlns:j4j="http://jbpm.org/jbpm4jsf/core"
          >
          
           <ui:define name="actions">
           <ga:responseActions>
           <ga:parameter name="id" target="#{piID}" required="true"/>
           <ga:parameter name="ppFileName" target="#{ppFileName}" required="true"/>
           <ga:parameter name="fileVar" target="#{fileVar}" required="true"/>
           <ga:parameter name="fileName" target="#{fileName}" required="true"/>
           <j4j:createUploadFile piID="#{piID}" ppFileName="#{ppFileName}" fileVar="#{fileVar}" fileName="#{fileName}" target="#{files}"/>
           </ga:responseActions>
           </ui:define>
          
           <gd:repeat value="#{files}" var="file" idVar="rid">
          
           <h:form enctype="multipart/form-data">
           <table>
           <thead>
           <tr>
           <th colspan="2">Upload
           <h:outputText value=" #{file.ppFileName} File"/>
           </th>
           </tr>
           </thead>
           <tbody class="results">
           <tr>
           <th>Upload</th>
           <td>
           <gd:inputFile target="#{stream}" maxSize="104857600"/>
           </td>
           </tr>
           <tr>
           <th/>
           <td style="text-align:right;">
           <h:commandButton value="Upload #{file.ppFileName}">
           <j4j:uploadFile archive="#{stream}" piID="#{file.piID}" fileVar="#{file.fileVar}" fileName="#{file.fileName}"/>
           <n:nav outcome="success" url="formSubmitted.jsf" storeMessages="true"/>
           <n:nav outcome="error" redirect="true" storeMessages="true"/>
           </h:commandButton>
           </td>
           </tr>
           </tbody>
           </table>
           </h:form>
          
           </gd:repeat>
          
          </html>
          


          I found that I couldn't pass the values straight into the form so I created an object containing the piID, ppFileName, etc. information. But this still didn't work and only seemed to work when I made it a list with only one element in it and pass it in through a loop. Maybe there's a less convuluted way of doing it, but I wasn't smart enough to find out how.

          In your upload file actionListener, all you have to do is to grab the InputStream and then write it out to a FileOutputStream that points to the filename you saved it under. You can actually refer to the JBPM team's DeployProcessActionListener.java code.

          Hope that helps

          David

          • 2. Re: Attaching files
            Varun Doda Newbie

            I have tried doing exactly the same. But, I am getting the following error.

            javax.servlet.ServletException: /sa/uploadFile.xhtml @20,131 <j4j:createUploadFile> Tag Library supports namespace: http://jbpm.org/jbpm4jsf/core, but no tag was defined for name: createUploadFile
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:249)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

            Can you help me in this?

            • 3. Re: Attaching files
              David Ling Newbie

              Hi,

              I think you need to develop the createUploadFile tag and package it as part of the jbpm4jsf-14.jar

              First you need the source code for org.jbpm.jsf.core.CoreLibrary.java and add the following line in there

              addTagHandler("createUploadFile", CreateUploadFileHandler.class);
              . Then create org.jbpm.jsf.core.handler.CreateUploadFileHandler.java as which calls org.jbpm.jsf.core.action.CreateUploadFileActionListener.java

              You can base your implementation on the Jbpm team's code, they are pretty straight forward.

              Make sure you return a
              List<UploadFileDAO>
              - with only one object in it, where UploadFileDAO.java is just a trivial Data Access Object that only contains the attributes I mentioned, such as piID, fileVar and fileName, a constructor and a bunch of getters/setters.

              Hope that helps

              David

              • 4. Re: Attaching files
                johnny sanchez Newbie

                Hi

                I'm stuck, in the part where you talk about modify CoreLibrary.java inside jbpm4jsf-14.jar, where can I get the sources of this jar file?

                david_ling please help me.

                Thank you in advance

                • 5. Re: Attaching files
                  johnny sanchez Newbie

                  Some people say that is not recomended to modify jbpm4jsf-14.jar, or any component of the jbpm console,

                  does anybody found another way to do this task?

                  thanks

                  • 6. Re: Attaching files
                    Ronald van Kuijk Master

                    yes, by just using e.g. richfaces and storing the file in your domain model, not the engine

                    • 7. Re: Attaching files
                      johnny sanchez Newbie

                      Thank you kukeltje for your answer ;)[/img]

                      • 8. Re: Attaching files
                        Shashank Jain Newbie

                         

                        "johnnyright" wrote:
                        Thank you kukeltje for your answer ;)[/img]

                        Were you able to use rich faces..Please guide me on this. I am unable to deploy the jbpm-console.war after adding rich faces libs..
                        Shashank

                        • 9. Re: Attaching files
                          Ronald van Kuijk Master

                          I do not adapt the jbpm-console. I leave that as is and use it what it is good for, admin purposes. For normal usage I developed my own webapp.

                          • 10. Re: Attaching files
                            Shashank Jain Newbie

                             

                            "kukeltje" wrote:
                            I do not adapt the jbpm-console. I leave that as is and use it what it is good for, admin purposes. For normal usage I developed my own webapp.


                            So in effect its a complete web application which allows you to start and run a workflow...
                            Will that be possible to share some parts of the code..
                            Shashank

                            • 11. Re: Attaching files
                              Ronald van Kuijk Master

                              uhhmmm..... I you seam... lots of examples there...

                              • 13. Re: Attaching files
                                Shashank Jain Newbie

                                 

                                "kukeltje" wrote:
                                you = use


                                Can you provide some links if possible. Thanks for the inputs

                                • 14. Re: Attaching files
                                  Shashank Jain Newbie

                                   

                                  "kukeltje" wrote:
                                  you = use


                                  Can you provide some links if possible. Thanks for the inputs

                                  1 2 Previous Next