cancel
Showing results for 
Search instead for 
Did you mean: 

New form type

car82
Champ in-the-making
Champ in-the-making
Hi all!!

I'm using Activiti and i want to create a new comboBox that  fills up with data from an external database. I'm following, the post: http://www.jorambarrez.be/blog/2013/03/13/creating-a-new-form-property-in-activiti/ .

My problem is that, after changing the xml configuration file and adding the jar file in the explorer directory in tomcat i have an 404 error when i try to start Activiti Explorer.

I create also an Integer form type and i don't have these problems.


p.s.: sorry for my english!!!!!!!!

java code:

public class ProdottoFinitoFormType extends AbstractFormType {
   private static final long serialVersionUID = 1L;

   RecuperoPF pf = new RecuperoPF();

   protected Map <String,String> values = pf.RecuperoDati();
   public ProdottoFinitoFormType(Map <String,String> values){
      this.values = values;
   }
   
   public String getName(){
      return "prodotto_finito";
   }
   
   @Override
     public Object getInformation(String key) {
       if (key.equals("values")) {
         return values;
       }
       return null;
     }

     @Override
     public Object convertFormValueToModelValue(String propertyValue) {
       validateValue(propertyValue);
       return propertyValue;
     }

     @Override
     public String convertModelValueToFormValue(Object modelValue) {
       if(modelValue != null) {
         if(!(modelValue instanceof String)) {
           throw new ActivitiIllegalArgumentException("Model value should be a String");
         }
         validateValue((String) modelValue);
       }
       return (String) modelValue;
     }
    
     protected void validateValue(String value) {
       if(value != null) {
         if(values != null && !values.containsKey(value)) {
           throw new ActivitiIllegalArgumentException("Invalid value for the form property: " + value);
         }
       }
     }

}



public class ProdottoFinitoFormPropertyRenderer  extends AbstractFormPropertyRenderer {
   
   public ProdottoFinitoFormPropertyRenderer() {
       super(ProdottoFinitoFormType.class);
     }
   
    @SuppressWarnings("unchecked")
     @Override
     public Field getPropertyField(FormProperty formProperty) {
       ComboBox comboBox = new ComboBox(getPropertyLabel(formProperty));
       comboBox.setRequired(formProperty.isRequired());
       comboBox.setRequiredError(getMessage(Messages.FORM_FIELD_REQUIRED, getPropertyLabel(formProperty)));
       comboBox.setEnabled(formProperty.isWritable());
       comboBox.setNullSelectionAllowed(false);
      
       Object firstItemId = null;
       Object itemToSelect = null;
       Map<String, String> values = (Map<String, String>) formProperty.getType().getInformation("values");
      
       if (values != null) {
           for (Entry<String, String> prodfinEntry : values.entrySet()) {
             // Add value and label (if any)
             comboBox.addItem(prodfinEntry.getKey());
            
             if (firstItemId == null) {
               firstItemId = prodfinEntry.getKey(); // select first element
             }
            
             String selectedValue = formProperty.getValue();
             if (selectedValue != null && selectedValue.equals(prodfinEntry.getKey())) {
               itemToSelect = prodfinEntry.getKey(); // select first element
             }
            
             if (prodfinEntry.getValue() != null) {
               comboBox.setItemCaption(prodfinEntry.getKey(), prodfinEntry.getValue());
             }
           }
         }
      
       // Select value or first element
       if (itemToSelect != null) {
         comboBox.select(itemToSelect);
        
       } else if (firstItemId != null) {
         comboBox.select(firstItemId);
       }
      
       return comboBox;
      
      
      
    }

}
2 REPLIES 2

jbarrez
Star Contributor
Star Contributor
There must be an exception stacktrace somewhere on bootup. Did you check your logs?

car82
Champ in-the-making
Champ in-the-making
The problem were in the FormType class, the new one is:

<java>public class ProdottoFinitoFormType extends AbstractFormType {
  public static final String TYPE_NAME = "prodottoFinito";
 
  public String getName() {
      return TYPE_NAME;
    }
 
  public Object convertFormValueToModelValue (String propertyValue){
   if(propertyValue != null) {
    return propertyValue;
   }
   return null;
  
  }
 
  public String convertModelValueToFormValue(Object modelValue){
   if (modelValue == null) {
        return null;
      }
   return modelValue.toString();
  }

}<java>

Now i can submit a string selected from an external database table and use read it.