cancel
Showing results for 
Search instead for 
Did you mean: 

Custom email selector form property - having issues understanding default data

ericsnyder
Champ on-the-rise
Champ on-the-rise
I am developing custom form property that is an email selector using a TwinColSelect. The heart of my issue is that I don't understand how to handle the data for the TwinColSelect. I need to prepopulate the property with some email addresses and then allow users to add their own as well. I will also need to get the email addresses selected in later email tasks to send the emails to these addresses.

I have created the custom form property and successfully used it in Explorer. I have learned how to prepopulate the values using the examples from the book and even learned how to preselect values. My two questions are:

1) How do I use the form values in the form definition (ID and Name) to populate the TwinColSelect. Mainly, how do I access the values I have predefined in the process definition?

2) Later, when the user selects their own choices what do I use to access these choices in an email task?

Code:
<!–break–>
My property renderer (I know, the code is really ugly right now):
   @Override   public Field getPropertyField(FormProperty formProperty) {      final TwinColSelect select = new TwinColSelect("Send status emails to:");                       Object formValues = formProperty.getType().getInformation("values");               // Put some data in the select         String emailList[] = {"Email one", "Email two", "Email three"};         for (int i=0; i<emailList.length; i++)             select.addItem(emailList);         //Set various list properties         select.setLeftColumnCaption("Choices");         select.setRightColumnCaption("Going to…");         select.setRows(5);         select.setNewItemsAllowed(true);                   // Preselect a few items         //Remove the first and last character                  String temp = formProperty.getValue();         if (temp != null){            temp = formProperty.getValue().substring(1);            temp = temp.substring(0, temp.length() - 1);            int numberOfEmails = StringUtils.countMatches(temp, ", ") + 1;            String[] emailData = new String[numberOfEmails];            if (numberOfEmails > 1){               emailData = temp.split(", ");            }else{               emailData[0] = temp;            }            //Be sure new added items make it in the list            for (int i=0; i<emailData.length; i++){               select.addItem(emailData);            }            HashSet<String> preselected = new HashSet<String>();            Collections.addAll(preselected, emailData);            select.setValue(preselected);            }         return select;       }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍


The task definition with the emailChecklist property defined:

    <userTask id="usertask1" name="First task" activiti:assignee="erics">      <extensionElements>        <activiti:formProperty id="desc" name="Decsription" type="textArea"></activiti:formProperty>        <activiti:formProperty id="emails" name="Emails" type="emailChecklist">          <activiti:value id="Testing1" name="Testing1"></activiti:value>          <activiti:value id="Testing2" name="Testing2"></activiti:value>        </activiti:formProperty>      </extensionElements>    </userTask>‍‍‍‍‍‍‍‍‍
2 REPLIES 2

ericsnyder
Champ on-the-rise
Champ on-the-rise
OK…
Here is what I have learned so far.
In this code fragment:
<java>public Field getPropertyField(FormProperty formProperty)</java> there is a FormProperty object. The form property object has the following information:
<code>id
isReadable
isRequired
isWriteable
name
type
value</code>
If you place a value in "default" it will be passed on to the value property. There is no property (that I can see) that passes some kind of a java collection with the information that you put in "Form Values". In other words, it looks like that gets ignored for custom form properties.

Bottom line on question #1 above: if I want to have default values then I will need to place them into the "Default" as a string and use those in my logic. Possibly a better way to get names and email addresses would be to enter all those that I need as users and query the user database or use the database in some way to store names/email addresses. Another way might be to use Drools.

Question #2 above: It looks like the value of my "emails" field is available at any time in the process definition by using ${emails}. I still have not figured out how to pull this info in a script though.

frederikherema1
Star Contributor
Star Contributor
#1: I presume you have overridden the initFormTypes() method on processEngineConfiguration (or use the setFormTypes(…) method) with a custom implementation of org.activiti.engine.impl.form.FormTypes. If not, create such a class that creates a FormType subclass specifically for your emailCheckList type, passing the "values" that are defined in the XML to the actual Type pojo, so you can access them (see org.activiti.explorer.ui.form.EnumFormPropertyRenderer where the values are extracted):


public AbstractFormType parseFormPropertyType(FormProperty formProperty) {
    if("emailCheckList".equals(formProperty.getType()) {
       Map<String, String> values = new LinkedHashMap<String, String>();
      for (FormValue formValue: formProperty.getFormValues()) {
        values.put(formValue.getId(), formValue.getName());
      }
      formType = new YourOwnFormType(values);
    } else {
       return super.parseFormPropertyType(…);
   }

#2: You mean a SciptTask? You can use "var mails = execution.getVariable("emails");" (if you're using javascript). The execution-object is exposed as a root-object in all scripting engines you use.