Showing a tree in embedded forms

217 views
Skip to first unread message

Armin Hasler

unread,
Mar 4, 2016, 10:37:33 AM3/4/16
to camunda BPM users
I want to show a tree in embedded forms and save the selected element. I started with external forms and added the Primefaces tree there and this worked well.

<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Auswahl</title>
</h:head>
<f:view>
<f:metadata>
<f:event type="preRenderView"
listener="#{camundaTaskForm.startTaskForm()}" />
</f:metadata>
<h:body>
<h:form>
<h3>Auswahl</h3>
<p:tree value="#{treeBean.root}" var="node" selectionMode="single" selection="#{processVariables['treeBean.selectedNode']}" dynamic="true">
<p:treeNode type="folder" expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{node}" />
</p:treeNode>
<p:treeNode type="document" icon="ui-icon-document">
<h:outputText value="#{node.getName()}" />
</p:treeNode>
</p:tree>
<h:commandButton id="submit_button" value="Bestätige Templateauswahl" action="#{camundaTaskForm.completeTask()}" />
<h:messages style="color:red;margin:8px;" />
</h:form>
</h:body>
</f:view>
</html>

But I need this as embedded form. Now I am a bit struggling how to proceed. Can you please give me a hint how to start this. I think this be possible using angularJS or jQuery, but I am a bit confused how to combine this with the cam-variable stuff?
Thank you

Sebastian Stamm

unread,
Mar 7, 2016, 4:42:21 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,

in embedded forms, you can only use plain HTML and Javascript, not JSF. The cam-variable-* attributes have to be added to the form fields, that contain the values of the process variables [1]. You can also add libraries globally to the tasklist and use them in the embedded form [2].

A good starting point would be the examples section of the documentation [3].

Cheers
Sebastian

armin.h...@gmail.com

unread,
Mar 7, 2016, 7:32:39 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,
I have already written embedded forms and used the cam-variable attributes. this works fine for me.
But the defined controls for embedded forms do not offer a Tree or sth. My tree is already implemented on the server side. My problem is how to present the tree on the frontend (with angularjs? I have never used it) and how to bind the selection of the tree to the cam-variable?

Sebastian Stamm

unread,
Mar 7, 2016, 8:13:54 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,

good to hear that embedded forms work for you :-)

The Tasklist does not provide a widget or component to render trees out of the box. You would have to include a script that provides that functionality (e.g. as an angular directive). Depending on the implementation of the tree, you might not be able to use the cam-variable-* directives, as they only work in the original form scope, but not in any child scope angular directives might create. You then would need to manage the variables yourself with Javascript [1].

Cheers
Sebastian

armin.h...@gmail.com

unread,
Mar 7, 2016, 10:25:56 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,
with your help, I found a different approach that would hopefully work in this case. I will try to build a tree structure in a select box.

What I need in this case is to access a list of objects in the embedded form. Like the following:

camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('templatesList');
});

camForm.on('variables-fetched', function() {
$scope.templatesList = camForm.variableManager.variable('templatesList').value;
});

But all camunda examples I found are accessing one object and its members. But I need to access a list of objects and loop over the objects.

Can you please give me a hint or guide me to an example how to do this client side in the form.
Thank you

Sebastian Stamm

unread,
Mar 7, 2016, 10:46:31 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,

I assume the type of your process variable templatesList is a Java object. If that is the case, you can have a look at how to work with Java Objects in embedded forms [1] as well as this example [2].

Cheers
Sebastian

armin.h...@gmail.com

unread,
Mar 7, 2016, 10:51:27 AM3/7/16
to camunda BPM users, armin.h...@gmail.com
Hi,
I was missing the ng-repeat. Sorry for that.

Thank you very much

armin.h...@gmail.com

unread,
Mar 8, 2016, 9:45:12 AM3/8/16
to camunda BPM users, armin.h...@gmail.com
From the examples and the documentation the objects are created only on client side.
I found this also in the documentation:

Out of the box, you can only work with Java Objects which are serialized in JSON format If Java Classes are serialized using JAX-B, you need to add custom XML parsing and writing logic to the embedded form. Java Objects serialized using Java Serialization cannot be used in forms.

Lets say I have created a list of objects on server side and put it with the Java Delegation into the scope execution.setVariable("documentTypeInfoWrapperList", documentTypeInfoWrapperList);

How can I access this list and the objects in the form?
What I tried in the form is:

<form role="form" name="branchForm">
<script cam-script type="text/form-script">

camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('documentTypeInfoWrapperList');
});

camForm.on('variables-fetched', function() {
$scope.documentTypeInfoWrapperList = camForm.variableManager.variable('documentTypeInfoWrapperList').value;
});

</script>
<div class="form-group">
<div ng-repeat="documentTypeInfoWrapper in documentTypeInfoWrapperList track by $index">
{{documentTypeInfoWrapper.getName()}}
<hr>
{{documentTypeInfoWrapper.name}}
</div>
</div>
</form>

From what I read in the docu <you need to add custom XML parsing and writing logic to the embedded form.> But how?

Sebastian Stamm

unread,
Mar 9, 2016, 3:38:46 AM3/9/16
to camunda BPM users, armin.h...@gmail.com
Hi,

if I understood you correctly, $scope.documentTypeInfoWrapperList contains the XML representation of your variable? If that is the case, you just need to parse this XML. I think the most comfortable way would be with a third party library you include in either the embedded form [1] or globally as a tasklist custom script [2].

Cheers
Sebastian

armin.h...@gmail.com

unread,
Mar 9, 2016, 5:11:52 AM3/9/16
to camunda BPM users, armin.h...@gmail.com
Hi,
no, documentTypeInfoWrapperList is a ArrayList of DocumentTypeInfoWrapper Objects. These are set in a former ServiceTask via

execution.setVariable("documentTypeInfoWrapperList", documentTypeInfoWrapperList);

which I want to access from client side over

camForm.on('form-loaded', function() {
camForm.variableManager.fetchVariable('documentTypeInfoWrapperList');
});

Sorry for the misunderstanding. I know JSF and I know Velocity template but I am new to the camForm and angular JS Stuff.

Sebastian Stamm

unread,
Mar 9, 2016, 7:11:44 AM3/9/16
to camunda BPM users, armin.h...@gmail.com
Hi,

sorry for the confusion :-) In Javascript, you do not have Objects like ArrayList or DocumentTypeInfoWrapper. So if you want to work with them in the embedded form (which uses Javascript), you have to transform them to a representation Javascript can work with (e.g. JSON). So the first step would be to have a look at the value of $scope.documentTypeInfoWrapperList (in the embedded form). My guess is, that it will look something like the JSON we use to create a variable in the documentation example [1].

Cheers
Sebastian

Reply all
Reply to author
Forward
0 new messages