[jboss-user] [JBoss jBPM] - Re: Attaching files

david_ling do-not-reply at jboss.com
Wed May 21 22:25:36 EDT 2008


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

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4152525#4152525

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4152525



More information about the jboss-user mailing list