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.

11 thoughts on “Using Activiti with Xform

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

  2. joernturner

    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 –

    Reply
  3. smirzai Post author

    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.

    Reply
  4. Gerardo cruz

    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 🙂

    Reply
    1. smirzai Post author

      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

      Reply
  5. Mehdi

    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?

    Reply
    1. Saeid

      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

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.