5 Replies Latest reply on Mar 23, 2012 7:28 AM by annah

    CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem

    sebb

      Currently I am working on my own CustomWorkItemEditor. In this editor I create an instance of MyDomainClass and fill its fields with some values from the editors text fields.

      In the WorkEditor.updateValue(Object) method I use an instance of WorkImpl and set the parameter by: work.setParameter("myParameter", myDomainClassInstance);

       

      My WorkItemDefinition uses the following type for "myParameter"

      "myParameter" : new ObjectDataType("my.package.MyDomainClass"),

       

      When I read the parameter inside my WorkItemHandler I dont get the instance of MyDomainClass, but a String object with the toString() representation of myDomainClassInstance.

      How can I get the real object and not the String object?

       

      Thanks in advance

       

       

      edit: To narrow it down:

      If I use IntegerDataType I get a String object either... Is this working as intended? Every object is transformed into a String?

        • 1. Re: CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem
          calca

          Hi Sebb,

           

          how are you passing the parameter to the node in your bpmn file?

           

          Demian

          • 2. Re: CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem
            sebb

            Hi Demian,

             

            I use my ServiceTask with my CustomWorkItemEditor to pass the parameters to the node (reduced to one parameter for this code example):

             

            public class MyDialog extends EditBeanDialog implements WorkEditor{

               

                Text myText;

               

                public MyDialog(Shell parentShell) {

                    super (parentShell, "title");

                    setBlockOnOpen(true);

                }

             

                protected Control createDialogArea(Composite parent) {

                    Composite composite = (Composite) super.createDialogArea(parent);

                    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);

                   

                    Work work = (Work) getValue();

                   

                       Label label = new Label(composite, SWT.NONE);

                    label.setText("labelOne:");

                    GridDataFactory.fillDefaults().applyTo(label);

                   

                    myText = new Text(composite, SWT.NONE);

                   

                    //get current value from node

                    MyDomainClass mdc = (MyDomainClass) work.getParameter("myParameter");

                    if(mdc != null){

                        Value value = mdc.getValue();

                        myText.setText(value == null ? "" : value.toString());

                    } else {

                        myText.setText("");

                    }

                    GridDataFactory.fillDefaults().applyTo(myText);

                }

                 

                protected Object updateValue(Object value) {

                    Work work = new WorkImpl();

                    work.setName(((Work) value).getName());

                          

                    MyDomainClass mdc = new MyDomainClass();

                    mdc.setValue(myText.getText());

                    work.setParameter("myParameter", mdc);

                    work.setParameterDefinitions(((Work) value).getParameterDefinitions());

                    return work;

                }

             

                public Work getWork() {

                    return (Work) getValue();

                }

             

                public void setWork(Work work) {

                    setValue(work);

                }

             

                public void setWorkDefinition(WorkDefinition workDefinition) {

                }

             

                public boolean show() {

                    int result = open();

                    return result == OK;

                }

            }

             

            WorkItemDefinition (reduced to one parameter for this code example):

             

            [

              [

                "name" : "MyServiceTask",

                "parameters" : [

                  "myParameter" : new ObjectDataType("my.package.MyDomainClass"),

                ],

                "displayName" : "do fancy stuff",

                "customEditor" : "my.package.MyDialog"

              ],

            ]

            • 3. Re: CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem
              sebb

              I just figured, that the problem does not start in the WorkItemHandler:

               

              See the code part with the comment: "//get current value from node"?

              There it happens also while editing my process. If I press OK to save my ServiceTask I cant open it again, because I dont get myDomainClassInstance, but a String object with the toString() representation of myDomainClassInstance...

               

              protected Control createDialogArea(Composite parent) {

              [...]

              //get current value from node

              MyDomainClass mdc = (MyDomainClass) work.getParameter("myParameter");

              [...]

              This code results to a ClassCastException because work.getParameter("myParameter") returns the above mentioned String.

               

               

              edit:

              Ok, I maybe found the problem. Since everything that is edited in my custom editor is pasted into the bpmn xml, I will never be able to get an object back from the process definition. As far as I can see I have to override the toString() method and create a parseable string that I can use to recreate the object I passed to the node.

               

              edit2:

              Now I am parsing my objects into json and save the json string in the bpmn file. Seems to work so far. But is this really the way to handle all parameters that are not Strings?

               

              Any opinions on this?

              • 4. Re: CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem
                sebb

                So this is the right way of handling domain objects in jbpm?

                • 5. Re: CustormWorkItemEditor + ObjectDataType("MyDomainClass"): Always getting String instead of MyDomainClass in WorkItem
                  annah

                  Hi!

                   

                  I have the exact same problem. I'm trying to pass an object of my custom class as a workItem parameter. Is this really the way to handle ObjectDataType parameters?