1 13 package com.tonbeller.wcf.convert; 14 15 import java.lang.reflect.InvocationTargetException ; 16 17 import org.apache.commons.beanutils.PropertyUtils; 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.wcf.format.FormatException; 21 import com.tonbeller.wcf.format.FormatHandler; 22 import com.tonbeller.wcf.format.Formatter; 23 import com.tonbeller.wcf.ui.Item; 24 import com.tonbeller.wcf.ui.SelectSingle; 25 26 37 public class SelectSingleConverter extends SelectConverterBase { 38 39 protected void updateModelReference(Formatter fmt, Element elem, Object bean) throws FormatException, IllegalAccessException , NoSuchMethodException , InvocationTargetException { 40 String model = SelectSingle.getModelReference(elem); 41 if (model.length() == 0) 42 return; 43 44 String type = SelectSingle.getType(elem); 45 String formatString = SelectSingle.getFormatString(elem); 46 FormatHandler parser = fmt.getHandler(type); 47 if (parser == null) 48 throw new FormatException("no handler found for type: " + type); 49 50 Element item = SelectSingle.getSelectedItem(elem); 51 if (item == null) 52 return; 53 54 String valueString = Item.getValue(item); 55 Object value = parser.parse(valueString, formatString); 56 PropertyUtils.setProperty(bean, model, value); 57 } 58 59 60 } 61 | Popular Tags |