List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty
public static void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:com.tonbeller.wcf.convert.BooleanConverter.java
/** * sets the selected attribute of the DOM element. If a modelReference * is specified, it must point to a boolean bean-property that will be updated. * * @param fmt Formatter for i18n string-object conversion * @param params parameters of http request * @param elem the target element.// w w w . ja v a 2s . co m * @param bean the target bean */ public void convert(Formatter fmt, Map params, Map fileParams, Element elem, Object bean) throws FormatException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { int state = isSelected(elem, params); if (state == UNKNOWN) return; // was the checkbox checked? Boolean value = new Boolean(state == TRUE); // set into elem and bean DomUtils.removeAttribute(elem, "error"); Item.setSelected(elem, value.booleanValue()); // update bean String modelReference = Item.getModelReference(elem); if (bean != null && modelReference.length() > 0) PropertyUtils.setProperty(bean, Item.getModelReference(elem), value); }
From source file:com.framework.infrastructure.utils.HibernateUtils.java
/** * ID,./*ww w. j a va 2s.co m*/ * * id,id. * id,id. ID, * cascade-save-or-update. * * @param srcObjects * ,. * @param checkedIds * ,ID. * @param clazz * * @param idName * */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { // Assert.notNull(srcObjects, "scrObjects"); Assert.hasText(idName, "idName"); Assert.notNull(clazz, "clazz"); // , . if (checkedIds == null) { srcObjects.clear(); return; } // ,idID,. // ,id,idid. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } // IDid,,id. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:com.khubla.cbean.serializer.impl.json.JSONArrayFieldSerializer.java
@Override public void deserialize(Object o, Field field, String value) throws SerializerException { try {//from w w w . ja v a 2s .c o m final JSONArray jsonArray = new JSONArray(value); final Object od = Array.newInstance(field.getType().getComponentType(), jsonArray.length()); PropertyUtils.setProperty(o, field.getName(), od); final Class<?> componentType = field.getType().getComponentType(); if (componentType.isPrimitive()) { for (int i = 0; i < jsonArray.length(); i++) { final String v = jsonArray.getString(i); PropertyUtils.setIndexedProperty(o, field.getName(), i, ConvertUtils.convert(v, field.getType().getComponentType())); } } else { final CBean<Object> cBean = CBeanServer.getInstance().getCBean(componentType); for (int i = 0; i < jsonArray.length(); i++) { final Object co = cBean.load(new CBeanKey(jsonArray.getString(i))); PropertyUtils.setIndexedProperty(o, field.getName(), i, ConvertUtils.convert(co, field.getType().getComponentType())); } } } catch (final Exception e) { throw new SerializerException(e); } }
From source file:com.mycollab.aspect.InjectTimeLoggingAspect.java
@Before("(execution(public * com.mycollab..service..*.updateWithSession(..)) || (execution(public * com.mycollab..service..*.updateSelectiveWithSession(..)))) && args(bean, username)") public void injectDateForUpdateMethod(JoinPoint joinPoint, Object bean, String username) { try {//from www. ja v a 2 s. c o m LOG.debug("Set createtime and lastupdatedtime if enable"); PropertyUtils.setProperty(bean, "lastupdatedtime", new GregorianCalendar().getTime()); } catch (Exception e) { } }
From source file:com.mycollab.module.crm.ui.components.RelatedItemSelectionWindow.java
public RelatedItemSelectionWindow(String title, RelatedListComp2 relatedList) { super(title); bodyContent = new MVerticalLayout(); this.withContent(bodyContent).withCenter().withModal(true).withResizable(false); this.relatedListComp = relatedList; initUI();/*from w w w .ja v a 2s .c om*/ tableItem.addTableListener(event -> { try { Object rowItem = event.getData(); Boolean selectedVal = (Boolean) PropertyUtils.getProperty(rowItem, selectedFieldName); if (selectedVal) { selectedItems.remove(rowItem); PropertyUtils.setProperty(rowItem, selectedFieldName, false); } else { selectedItems.add(rowItem); PropertyUtils.setProperty(rowItem, selectedFieldName, true); } } catch (Exception ex) { throw new MyCollabException(ex); } }); }
From source file:com.hula.lang.util.DotNotationUtil.java
public static void setProperty(String name, Object source, Object value, int index) { // last item in the path is the target property name ////w w w . j av a2 s . co m // i.e. script.description // // we're looking up to script, then to description String targetProperty = getLastItem(name); String[] path = getPath(name); // refine the source down to the correct object for (int i = index; index != path.length - 1; index++) { String item = path[i]; source = reflect(source, item); } // now do the set try { PropertyUtils.setProperty(source, targetProperty, value); } catch (Throwable t) { t.printStackTrace(); } }
From source file:hermes.renderers.RendererHelper.java
/** * Create a default renderer for a Config that just contains simple * properties (i.e. not 1:m relationships), the dialog will be a normal * property pane.//from ww w. j a v a 2s . c o m * * @param dialogProxy * @return @throws * IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ public static JComponent createDefaultConfigPanel(final ConfigDialogProxy dialogProxy) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { final Config theConfig = dialogProxy.getConfig(); final List<Property> list = new ArrayList<Property>(); final Map properties = PropertyUtils.describe(theConfig); for (Iterator iter = properties.entrySet().iterator(); iter.hasNext();) { final Map.Entry entry = (Map.Entry) iter.next(); final String propertyName = (String) entry.getKey(); final Object propertyValue = entry.getValue(); if (!propertyName.equals("class") && !propertyName.equals("name")) { Property displayProperty = new Property(propertyName, theConfig.getPropertyDescription(propertyName), propertyValue.getClass()) { /** * */ private static final long serialVersionUID = -4650355524853942976L; public void setValue(Object value) { try { dialogProxy.setDirty(); PropertyUtils.setProperty(theConfig, propertyName, value); } catch (Exception e) { cat.error(e.getMessage(), e); } } public Object getValue() { try { return PropertyUtils.getProperty(theConfig, propertyName); } catch (Exception e) { cat.error(e.getMessage(), e); } return null; } public boolean hasValue() { return true; } }; list.add(displayProperty); } } PropertyTableModel model = new PropertyTableModel(list); PropertyTable table = new PropertyTable(model); table.setAutoResizeMode(PropertyTable.AUTO_RESIZE_ALL_COLUMNS); PropertyPane pane = new PropertyPane(table); pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { dialogProxy.setDirty(); } }); model.expandAll(); return pane; }
From source file:com.esofthead.mycollab.common.interceptor.aspect.InjectTimeLoggingAspect.java
@Before("(execution(public * com.esofthead.mycollab..service..*.updateWithSession(..)) || (execution(public * com.esofthead.mycollab..service..*.updateSelectiveWithSession(..)))) && args(bean, username)") public void injectDateForUpdateMethod(JoinPoint joinPoint, Object bean, String username) { try {//from w w w .j a v a2 s .co m LOG.debug("Set createtime and lastupdatedtime if enable"); PropertyUtils.setProperty(bean, "lastupdatedtime", new GregorianCalendar().getTime()); } catch (Exception e) { } }
From source file:com.xyz.util.WebDataUtil.java
/** * ?ID?,???./*w ww .j ava2 s . c o m*/ * * ??????id,??????id?????. * ???id?ID?,?ID?id??. * * @param srcObjects ?? * @param checkedIds ID? * @param clazz ? * @param idName ?? */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { //? Assert.notNull(srcObjects, "scrObjects?"); Assert.hasText(idName, "idName?"); Assert.notNull(clazz, "clazz?"); //ID?,???. if (checkedIds == null) { srcObjects.clear(); return; } //????,id?ID?,. //?,ID???id,ID?id???ID. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } //ID??id????,,id??. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtil.convertToUncheckedException(e); } }
From source file:io.github.benas.projector.processors.AbstractAnnotationProcessor.java
/** * Convert the value to field type and set it in the target object. * * @param target the target object/*from w w w. j a v a2 s . c om*/ * @param field the annotated field * @param key the annotation property attribute * @param value the value to inject * @throws Exception thrown if an exception occurs when trying to set the field value */ protected void injectProperty(Object target, Field field, String key, Object value) throws Exception { Object typedValue = ConvertUtils.convert(value, field.getType()); try { PropertyUtils.setProperty(target, field.getName(), typedValue); } catch (Exception e) { throw new Exception("Unable to set property " + key + " on field " + field.getName() + " of type " + target.getClass() + ". A setter may be missing for this field.", e); } }