working with java objects in bonita 6.*

1
+1
-1

Hello, I’m trying to work with java objects in Bonita 6.2.4 and I had fallowed the next steps Create a serializable class, thi is it:

package DataTypes;

import java.io.Serializable;

public class Persona implements Serializable {
        private static final long serialVersionUID = -7285183091396405846L;
        private String nombre;
        private int edad;
        private boolean  universitario;
       
       
       
        public String getNombre() {
                return nombre;
        }
        public void setNombre(String nombre) {
                this.nombre = nombre;
        }
        public int getEdad() {
                return edad;
        }
        public void setEdad(int edad) {
                this.edad = edad;
        }
        public boolean isUniversitario() {
                return universitario;
        }
        public void setUniversitario(boolean universitario) {
                this.universitario = universitario;
        }      
}

Export this class as a jar. Then in Bonita I went to Development-> Manage jars and imported it. Then I created a variable with name persona in my process and I assigned it the type DataTypes.Persona Create a groovy script in the default value field with this code:

import DataTypes.Persona;
Persona persona = new Persona();
return persona;

DataTypes.Persona appears as a posible type to choose while I’m writing my code.

Now, when I run my process I get this error:

GRAVE: It is not possible to start the apps. Please contact your administrator org.bonitasoft.engine.bpm.process.ProcessExecutionException: org.bonitasoft.engine.core.process.instance.api.exceptions.SProcessInstanceCreationException: org.bonitasoft.engine.core.process.instance.api.exceptions.SProcessInstanceCreationException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1: unable to resolve class DataTypes.Persona @ line 1, column 1. import DataTypes.Persona; ^ Why is this error? what should I do? Other question After to solve this, how could I will be able to assign values of my form widgets to the java object attributes? The mapping options only let me choose between process variable an the all persona object, as I see I can´t write a script in that field to access the setters. Thanks in advance

1 answer

1
+1
-1
This one is the BEST answer!

Hi,

As far as I can remember try adding the dependency in the server part (ie Server -> Configure -> Process dependencies -> check "Other")

The developpement part is just for name recognition (as you noticed)

If you want to get directly your object from within your form fields i would say that you may want to create a process variable with the type of a Java Object and select your business class as the specialized type.

If you want to set a member value in your custom object using an accessor you have to:

select your form field and look at the general -> data pannel select your object as the left value the output operation operande click on the method between left and right operande (sthing like take value of) select your setter method make sure your form field is selected as the right operande

NOTA: it is assumed that your object is instanciated (eg: define its default value at the process data definition level and return the instance from within a script)

Hope this will help,

Comments

Submitted by Ray14 on Wed, 04/23/2014 - 21:22

hello aCordier, and thanks for your answer, I did the change and now it recognize Persona as a type but a still don´t know how to assign values of my form widgets to the java object attributes

Submitted by aCordier on Wed, 04/23/2014 - 21:41

Well, I would say the best is to define a process data, select java object as its type and access its reference as any other process process variable from your form field. - See more at: http://community.bonitasoft.com//answers/working-java-objects-bonita-6#s...

Submitted by aCordier on Thu, 04/24/2014 - 09:42

I edited my answer to address this point.

Submitted by Ray14 on Thu, 04/24/2014 - 15:55

Hello again aCordier , and thanks for your help, as I told before: I created a variable with name persona in my process and I assigned it the type DataTypes.Persona The doubt comes because when I going to map the process variables with the form fileds in a task form I can select only the whole variable of the java object type (in this case the persona variable with the type DataTypes.Persona ) I don’t have access to the setters methods (for instance if I want to assign a value to the nombre attribute form a text field I can’t because the mapping options only allow to select a variable name and don’t allow to write code), so when I selected the variable persona and mapped it with a text field, types do not match(DataTypes.Persona != String). The question is how to map a value from a form field to a java object attribute, where I can tell something like this: persona.setNombre(field_Text1) or this: persona.nombre = field_Text1?

Submitted by aCordier on Thu, 04/24/2014 - 16:12

Hello, I edited my answer again

Submitted by Ray14 on Thu, 04/24/2014 - 16:20

I haven’t noticed that I could change that method, problem solved, thanks a lot.

Notifications