[jboss-user] [JBoss jBPM] - Re: Signal a task on a html form submit
cahimoped
do-not-reply at jboss.com
Tue May 29 03:51:14 EDT 2007
Ok I post you some code and informations... It will not say more that I already said... but ok let's go.
Here is my task :
<task-node name="Creer bilan">
| <task name="bilanCP">
| <assignment actor-id="#{CP}" />
| </task>
| <transition to="Evaluation DP" name="OK"></transition>
| </task-node>
|
Here is my association in the forms.xml :
<form task="bilanCP" form="bilanCP.xhtml"/>
Here is my bilanCP.xhtml (displaying well) :
<!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:c="http://java.sun.com/jstl/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:tf="http://jbpm.org/jsf/tf"
| xmlns:jbpm="http://jbpm.org/jsf">
|
| <ui:component>
| <form enctype="multipart/form-data" method="POST" action="uploadSuivi">
| <jbpm:dataform>
| <f:facet name="header">
| Envoyer un fichier local
| </f:facet>
| <jbpm:datacell>
| <f:facet name="header">
| Selectionnez le fichier a envoyer :
| </f:facet>
| <input class="file" type="file" name="suiviXLS"/>
| <input name="nomProjet" type="hidden" value="#{var['nomProjet']}"/>
| <input name="tokenId" type="hidden" value="#{token.getId}"/>
| </jbpm:datacell>
|
| <jbpm:datacell>
| <f:facet name="header">
| <h:outputText value="Actions"/>
| </f:facet>
| <button class="button" type="submit">Envoyer</button>
| </jbpm:datacell>
|
| </jbpm:dataform>
| </form>
|
| <br />
|
| <jbpm:dataform>
| <f:facet name="header">
| <h:outputText value="Fichier distant modifie"/>
| </f:facet>
|
| <jbpm:datacell>
| <f:facet name="header">
| <h:outputText value="Actions"/>
| </f:facet>
| <!-- TASKFORM BUTTONS -->
| <tf:transitionButton transition="OK" value="Faire suivre le fichier au DP"/>
| </jbpm:datacell>
| </jbpm:dataform>
|
| </ui:component>
|
| </html>
|
and here is my servlet :
import java.io.File;
| import java.io.IOException;
| import java.io.PrintWriter;
| import java.util.Iterator;
| import java.util.List;
|
| import javax.servlet.http.HttpServlet;
| import javax.servlet.http.HttpServletRequest;
| import javax.servlet.http.HttpServletResponse;
|
| import org.apache.commons.fileupload.FileItem;
| import org.apache.commons.fileupload.FileItemFactory;
| import org.apache.commons.fileupload.servlet.ServletFileUpload;
| import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
| public class UploadSuivi extends HttpServlet {
|
| private static final long serialVersionUID = -7214369336993351418L;
|
| private FileItem fichier;
| private String nomProjet;
| private String tokenId;
|
| public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
| if (!ServletFileUpload.isMultipartContent(request)) {
| throw new RuntimeException("Not a multipart request");
| }
|
| try {
| // Create a factory for disk-based file items
| FileItemFactory factory = new DiskFileItemFactory();
|
| // Create a new file upload handler
| ServletFileUpload upload = new ServletFileUpload(factory);
|
| // Parse the request
| List list = upload.parseRequest(request);
|
| // Process the uploaded items
|
| for (int i=0; i<list.size(); i++) {
| FileItem item = (FileItem) list.get(i);
|
| if (item.getFieldName().compareTo("suiviXLS") == 0) {
| fichier = item;
| }
|
| if (item.getFieldName().compareTo("nomProjet") == 0) {
| nomProjet=item.getString();
| }
|
| if (item.getFieldName().compareTo("tokenId") == 0) {
| tokenId=item.getString();
| }
| }
|
| // save the file
| File uploadedFile = new File("C:/"+nomProjet+".xls");
| fichier.write(uploadedFile);
|
| // signal the task
|
| // redirtection vers la page des taches
| response.sendRedirect(response.encodeRedirectURL("search/tasks.jsf"));
| } catch (Exception e) {
| throw new RuntimeException("Exception quelque part...", e);
| }
| }
| }
|
The code is ugly, I know, it's because it's not finished at all...
At the end of the execution I got my file, my project name variable in nomProjet and an empty string in tokenId (so it goes in the if statement and does the getString on the third item).
I understand that my token.getId should work from this part of documentation (section 18.3, I can copy paste it: it's really short) and the link given to EL:
For some of the delegations, there is support for a JSP/JSF EL like expression language. In actions, assignments and decision conditions, you can write an expression like e.g. expression="#{myVar.handler[assignments].assign}"
|
| The basics of this expression language can be found in the J2EE tutorial.
|
| The jPDL expression language is similar to the JSF expression language. Meaning that jPDL EL is based on JSP EL, but it uses #{...} notation and that it includes support for method binding.
|
| Depending on the context, the process variables or task instance variables can be used as starting variables along with the following implicit objects:
|
| * taskInstance (org.jbpm.taskmgmt.exe.TaskInstance)
| * processInstance (org.jbpm.graph.exe.ProcessInstance)
| * processDefinition (org.jbpm.graph.def.ProcessDefinition)
| * token (org.jbpm.graph.exe.Token)
| * taskMgmtInstance (org.jbpm.taskmgmt.exe.TaskMgmtInstance)
| * contextInstance (org.jbpm.context.exe.ContextInstance)
I'm not an expert in all the JSF and EL and even if I didn't find anything to help me looking these parts.
I'm using the jBPM 3.2 suite (sorry I forgot to mention that) and GPD 3.0.13 to deploy and have the process definition and forms skeleton (I write a lot by myself after... I'm waiting the new GPD (seems great) to leave the alpha and beta states before using it :) ).
If you want to know everything :
- I customize the example web application to fit my needs by removing some administration parts, adding servlets and others things I need,
- I begin to use the new admin console from CVS (I think I will somehow merge the two at the end),
- my shoes size is 10 and... ok I stop here :)
Hope it helps...
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049208#4049208
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049208
More information about the jboss-user
mailing list