AnsweredAssumed Answered

New form type

Question asked by car82 on May 20, 2015
Latest reply on Jun 19, 2015 by car82
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;
      
      
      
    }

}

Outcomes