1 13 package com.tonbeller.wcf.convert; 14 15 import java.lang.reflect.InvocationTargetException ; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 import java.util.List ; 19 20 import org.apache.commons.beanutils.PropertyUtils; 21 import org.w3c.dom.Element ; 22 23 import com.tonbeller.wcf.format.FormatException; 24 import com.tonbeller.wcf.format.FormatHandler; 25 import com.tonbeller.wcf.format.Formatter; 26 import com.tonbeller.wcf.ui.Item; 27 import com.tonbeller.wcf.ui.SelectMultiple; 28 29 40 public class SelectMultipleConverter extends SelectConverterBase { 41 42 45 protected void updateModelReference(Formatter fmt, Element elem, Object bean) 46 throws FormatException, IllegalAccessException , NoSuchMethodException , InvocationTargetException { 47 48 String model = SelectMultiple.getModelReference(elem); 49 if (model.length() == 0) 50 return; 51 52 String type = SelectMultiple.getType(elem); 53 String formatString = SelectMultiple.getFormatString(elem); 54 FormatHandler parser = fmt.getHandler(type); 55 if (parser == null) 56 throw new FormatException("no handler found for type: " + type); 57 58 List items = SelectMultiple.getSelectedItems(elem); 59 checkRequired(fmt.getLocale(), elem, items.size() == 0); 60 List values = new ArrayList (); 61 62 for (Iterator it = items.iterator(); it.hasNext();) { 63 Element item = (Element )it.next(); 64 String valueString = Item.getValue(item); 65 Object value = parser.parse(valueString, formatString); 66 values.add(value); 67 } 68 69 PropertyUtils.setProperty(bean, model, parser.toNativeArray(values)); 70 } 71 72 73 } 74 | Popular Tags |