Using Activiti with Xform

Preface:

Thank you Joram to motivate me to write this post and explains what is mentioned in this post in more details.

We are using Activi in our company. Activiti provides an explorer application which is based on Vaadin. Vaadin is a Javascript based web framwork and extends Google GWT.

My first problem with this approach is that a new protocol for form definition is created from scratch. There are already mature form definition protocols with lots of open source and commercial implementations available. So why to reinvent the wheel ? Xform maybe the best standard available today. It is a little bit old and forgotten, but still works fine.

My second problem is the framework used. Vaadin is wonderful, but it is not easy to integrate it with other main stream servlet based frameworks.

First I tried to make current Vaadin based implementation to use Xform instead of home made protocol used in it. I spent several days on the subject and was persuaded that it is not easy if not impossible. One of the problems is discussed here in Vaadin forum.

To select a rendering engine, first I took ronal.van.kuik’s advice in this thread and selected BetterForms open source Xforms implementation. I was not able to configure it properly to work well in a short time. So I tested Orbeon, another open source implementation.This time it went well. I was able to create a proof of concept easily. Here I explain how it works.

Orbeon Integration

First of all Orbeon needs to be installed on the tomcat. Orbeon could be configured to process the Xforms for another application. First it should be deployed as a seperate web application, say /orbeon. It is a stand alone application with a nice user interface for management and even designing new forms. But what we need here is the form rendering functionality. For this, a jar file should be copied in the application and configured as a filter. This filter checks the HTTP traffic and renders any xforms content in it.

Details for configuration of Orbeon could be found here. Installation is very straight forward.  I used “seperate configuration” option, though “Integrated application” also does not seem to be much different.

Xforms file assignment

The next step is to define a standard for assigning the user task to a specific xforms file. Our application uses static tapestry forms. It is desired that application be backward compatible and can support traditional static forms. For this, I selected to add an “xform:” string to the start of the form name, if it is going to be rendered by Xforms engine. Else it will be processed as usual.   Here is how the definition looks like:

<userTask
id="utProvideMerchantMainInfo" name="Provide merchant main info"
activiti:formKey="xforms:merchant/ProvideMerchantMainInfo">
</userTask>

Rendering Xforms 

Now is the time to do the main part of the job and render the form. The form reading should be dynamic. As Orbeon filter is configured, it is enough to copy the content of xforms  file to  http output. To do this, i have created a Servlet. This servlet simply, gets the file name containing xform from a request parameter and copies the content of the file to http stream.

Here is the code for servlet:

String formName = request.getParameter(PARAM_XFORM_NAME);
String resourceName = "/xforms/" + formName + ".xhtml";
String line;
Writer writer = response.getWriter();
while ((line = reader.readLine()) != null) {
writer.write(line);
}

and here is its mapping in web.xml


<servlet>
<servlet-name>xformActiviti</servlet-name>
<servlet-class>net.atos.xa.mac.admin.xform.XformsRendererServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>xformActiviti</servlet-name>
<url-pattern>/xforms/renderer</url-pattern>
</servlet-mapping>

now in the application, it is enough to set the file name parameter and forward the page to renderer servlet:

if (formPrefix == FormPrefix.XFORMS) {
formKey = FormPrefix.removePrefix(formKey);
Link link = new LinkImpl("/xa-mac-admin" + "/xforms/renderer", false,
false, response, null);
link.addParameter(XformsRendererServlet.PARAM_XFORM_NAME, formKey);
link.addParameter("taskId", taskId);
return link;

That was the main part, now the form is rendered by orbeon filter. Orbeon filter, also cares for events and ajax like interactions.

Submitting the xform

After the user sees the rendered xform, he fills into the fields and submits the form. In Xform standard, xforms:submission is responsible for this. Xform engine creates an xml file with from input data and sends the generated xml to the url mentioned in xforms:submission tag.

here is a sample value for this tag in our xform:

<xforms:submission action="http://localhost:8080/xa-mac-admin/xforms/submit" method="post"
id="submit" includenamespaceprefixes="" />

The xml is sent to the above url. Again we need a servlet to receive xml file, parse it and complete the task. The source for the code is a little bit long and trivial.

Initial values of  xform fields

The above procedure was the first step and usually the form in this step is clear. But it is probable that in the next steps, some of the previously input data should be shown. Again for this purpose, an xml document should be created and sent to Xform engine.

This entry was posted in activiti and tagged . Bookmark the permalink.

25 Responses to Using Activiti with Xform

  1. Pingback: Using Activiti with XForm (or why having a community rocks!) | Small steps with big feet

  2. joernturner says:

    What a pity you didn’t ask. We would definitely helped doing that integration as actually betterFORM is very easy to integrate. Just some jars and some config in web.xml. Maybe not too late…

    Joern Turner
    – betterFORM –

    • Navid says:

      Dear Joeron
      Is it possible for you to explain the integration of betterForm and Activiti in more details?
      Thank you
      Navid

  3. smirzai says:

    Hi Joern
    Thank you for your attention. You are right, I should have asked.
    I try to take your offer and find some time slot to make it also work with betterform using your helps.

  4. joernturner says:

    Just let me know. I would love to use Activiti with betterFORM 😉

  5. Gerardo cruz says:

    Hi everyone,

    I am Gerardo, Im from México. I am in charge of a process-based web application in my job which is build with Spring, Spring Web Flow, PrimeFaces and JPA. I am using Activiti as process engine embedded in the web application. Actually we were planning to do our own rendering engine for bulding forms used in UserTasks using PrimeFaces for the view. I read this post and seems very useful to do the same with XForms and not trying to reinvent the wheel. We just need something to buld forms separatelly from the webapp and the webapp can use them and render them without any problem when a UserTask is reached, Was this the same use case you had? In that case I wonder if you can provide the source code of any good example you have in order to have an idea about what and how can I do this.

    Additionally, I toke a look into the Orbeon and BetterForms web pages, and I realized that Orbean has Coomunity and Professional Editions, do you think the community eddition is enough to use it as designing and rendering tool? Is Orbeon the best choice or could be possible to consider BetterForms as an option?

    Thanks 🙂

    • smirzai says:

      Hi Gerardi,
      Yes this is exactly the purpose of this sample pilot. I think it is a generic need. My sample is written in Tapestry and not directly usable in your case. If you think it can help you, please let me to sent it to you.
      I was thinking of creating a general purpose user task, based on pluggable form generator and specifically Xforms and donate it to Activiti open source. Do you think you can also work on it? Lets make others use of what you have done. Isn’t it the philosophy of open source after all ?

      As I have written, for me it was easier to do the integration using orbeons. But it was just a personal experience. As you can see in the comments joern from betterform has declared that it is also easy to do the same in betterform and he is ready to help. I am also curious to check again, this time with his helps.

      — Saeid

      • fingcode says:

        I can help on this, maybe we could make a project open source yo integrate activiti and xform

      • James Cen says:

        Hi Saeid,
        I am interested in using Tapestry for forms with Activiti. Is it possible to forward your sample code?

        I am comfortable with the latest Tapestry and getting comfortable with Activiti. Your sample code might just be the spark I need to move things forward.

        Thanks for your help in advance.

        James

      • smirzai says:

        Hi James,
        sent in an email.

        — Saeid

  6. liu says:

    Hi smirzai:
    Would you give me the web.xml code( integrated deployment) . thank you .

  7. lsimokaitis says:

    Hi, would it be possible to get the source of this proof of concept ?

  8. Navid says:

    Dear Saeid
    is it possible to send the web.xml too. thank you

  9. Mehdi says:

    Hi smirzai,

    I know maybe here is not the best place to ask my question but It is really impossible to find your email on the internet!
    I actually have a question about the integration of Activiti 5 and JSF 1.2. We have a customized framework which is based on Spring 2.5 + JSF 1.2 (Icefaces 1.8) + Hibernate. We have used JSF as the view layer framework and have built so many components on top of that to create required forms element including LOV (list of values), editable datagrids and so on, on the fly.

    Currently my company has decided to add a workflow engine to the framework without changing anything in the infrastructure. In other words, now we have some in-production projects with a lot of complex forms and we need to somehow add the workflow functionality to them. I googled a lot to find a solution to tackle this problem and found out Activiti has an out of the box feature for integration with Spring. But, currently I encountered with a new obstacle which I did not find any solution for. I need to use my old forms (based on JSF 1.2) as the User tasks (Human Intraction) in the workflow process but it seems the only way to handle it, is using CDI module to make a connection between Avtiviti and JSF. Unfortunately we have not used CDI as a bridge between Java beans and View pages, instead we have used “JSF managed bean”!

    I was wondering whether it is possible in Avtiviti to use “JSF managed bean” to make the mentioned bridge or we must switch to CDI?

    • smirzai says:

      Hi Mehdi

      Form handling is not an essential part of activiti. If you do not want to use VADIN based “Activiti explorer”, then you are on your own. You can have your complex forms, and just int he submit button, you need to call TaskService.complete(String taskId, Map variables) function. To do that you only need, TaskService and taskId and you can use any injection mechanism or even nothing to gain them.
      So there is nothing to worry about when using your own JSF based forms.
      Do not hesitate to ask if you think I can help more.

      Regards
      Saeid

  10. Balvinder says:

    Hi Saeid,

    I am interested in integrating Orbean XForms with Activiti, and have few questions.

    My requirement is workflow centric, where most of the steps in the workflow are user task ( human task) where a user completes a form and submits it, then another user assesses the form, and fills an assessment form and submits it, and so on.

    1) I have a requirement for a user dashboard, where user will get notifications, view and action tasks, application-admin user (different role) can assign tasks to other users. Can we still use Activiti Explorer? and sort of launch XForms from Activiti Explorer? or will have to build a complete custom user dashboard and interact with Activiti Engine via the REST API to provide this functionality?
    2) In your example above, “Submitting the xform”, how are the validations on the Xforms handled? e.g. presumable validations are server side (in Orbean XForms), so we cannot progress the workflow to next step until we know if the form had any validation errors and hence not submitted yet?
    3) Will it be possible to share the submission example? Would we have to parse the XML before dispatching it to Orbeon Forms Engine? if we don’t need any values from submitted XML
    4) Also section “Initial values of Xform fields”, presumably this is when you would parse the submitted XML, and build another xml message for the next step in the workflow? do you have an example code snippet you can share?

    Thanks for your help, this article has been very useful.

    Regards,
    Balvinder

    • smirzai says:

      Hi Balvinder,

      Glad to see someone else is also working on that topic.
      Here are answers:
      1. Actually task listing and peeking has nothing to do with xforms part. You can use what is already available in explorer, but you have to be aware that it uses Vaadin. I was not successful to integrate Javabased Vaadin with Orbeon. Ordbeon is a sevlet based technology and might not be easy to be integrated with Vaadin. But that can be because of my lack of knowledge in Vaadin. There is a thread in Vaadin forum. Let me know if you need it. I can find the link.
      2. Yes, you can define validations in Xform itself. Renderer only send the request when the form is validated. I Don’t remember it is server side or client side, though.
      3. I am going to do it. I need to find some part. It was a POC for company, I have to cut the company specific parts and share the rest. Try to do soon. Any communication with Orbeon would be in form of xml.
      4. More than usual you need to show some information from workflow in the form and get data from user. It was the first part I meant. It was about how to feed the rendered form with initial data got from workflow variables

  11. Shailesh says:

    Hi Saeid,

    Could you please send me your code at shail2smart@yahoo.co.uk

    Thanks,
    Shail

    • smirzai says:

      Hi Shail,
      I have to clean it and remove the company specific parts from it. I will try to update you when it is done.

      saeid

      • Shailesh says:

        Thanks for your reply Saeid. The reason for asking for source code is because I am struggling to make this work using Activiti explorer. Have you tried running this process from Activiti explorer?

        Am I missing something in code below?

        I have done all other configuration and servlets as stated above and Orbeon guide.

  12. smirzai says:

    Hi
    No, I was not able to make it work with Vaadin and Orbeon. There are some discussion in Vaadin forum about it as well. You need to find a Vaadin implementation of Xforms. What I used, was Orbeon, which is a servlet based xforms implementation. I was not able to mix servlet based and javascript based technologies.

  13. Somy says:

    Hi Saeid,
    I have a question: why Vaadin? Is that worth to use Vaadin for presentation layer when there are Jsf or other frameworks? It need too many java code. Maybe I don’t know more about it but I should say it really made some problem for me to modify a piece of page of an outsource project; for example I need to have a timer for my session, Vaadin doesn’t let me to use JavaScript, so I should write it server-side, although other technologies represent this client-side. Another problem, it doesn’t let me to update the label automatically without Refresher!
    I was wondering what’s the beneficial of using Vaadin combined with Activiti?

    • smirzai says:

      Hi Somy
      At that time GWT and a little bit better Vaadin were trend for the responsive web gui’s.
      Nowadays it is not like that. The Activiti explorer is rewritten with Vaadin parts removed. It is ported to Angular.js
      It will be soon released in Release 6.0

Leave a comment