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:mojo.view.util.BeanUtils.java
public static void setProperty(Object obj, String prop, Object val) { try {/*ww w . ja va 2 s. c om*/ PropertyUtils.setProperty(obj, prop, val); } catch (Exception e) { // do nothing } }
From source file:com.dotosoft.dot4command.utils.BeanUtils.java
public static void setPropertyValue(Object data, String name, Object value) { try {/*from ww w . ja v a 2 s.c o m*/ PropertyUtils.setProperty(data, name, value); } catch (Exception ex) { } }
From source file:com.googlecode.commons.swing.util.BeanUtils.java
public static void setProperty(Object bean, String property, Object value) { try {// w w w. ja va 2 s. c o m PropertyUtils.setProperty(bean, property, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } }
From source file:jp.terasoluna.fw.util.BeanUtil.java
/** * ??JavaBean????/*from w ww . j a v a 2 s .c o m*/ * * @param bean * ????JavaBean * @param property * JavaBean? * @param value * ?? * @throws PropertyAccessException * ?????? */ public static void setBeanProperty(Object bean, String property, Object value) throws PropertyAccessException { try { // PropertyUtils.setProperty(bean, property, value); } catch (IllegalArgumentException e) { throw new PropertyAccessException(e); } catch (IllegalAccessException e) { throw new PropertyAccessException(e); } catch (InvocationTargetException e) { throw new PropertyAccessException(e.getTargetException()); } catch (NoSuchMethodException e) { throw new PropertyAccessException(e); } }
From source file:com.jythonui.server.BUtil.java
private static void setPerson(Object o, String propName, String person) { if (person == null) return;/*from w w w .j a v a 2s . c om*/ try { PropertyUtils.setProperty(o, propName, person); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { } }
From source file:com.aosa.main.utils.tools.AOSACopyUtil.java
/** * Description<code>Copy properties of orig to dest Exception the Entity and Collection Type</code> <br> * By mutou at 2011-8-30 ?11:35:29 <br> * Object <br>/*from ww w . ja va2s . com*/ * @param dest * @param orig * @return the dest bean * @throws */ @SuppressWarnings("rawtypes") public static Object copyProperties(Object dest, Object orig) { if (dest == null || orig == null) { return dest; } PropertyDescriptor[] destDesc = PropertyUtils.getPropertyDescriptors(dest); try { for (int i = 0; i < destDesc.length; i++) { Class destType = destDesc[i].getPropertyType(); Class origType = PropertyUtils.getPropertyType(orig, destDesc[i].getName()); if (destType != null && destType.equals(origType) && !destType.equals(Class.class)) { if (!Collection.class.isAssignableFrom(origType)) { try { Object value = PropertyUtils.getProperty(orig, destDesc[i].getName()); PropertyUtils.setProperty(dest, destDesc[i].getName(), value); } catch (Exception ex) { } } } } return dest; } catch (Exception ex) { throw new AOSARuntimeException(ex); } }
From source file:com.nec.nsgui.action.cifs.CommonUtil.java
/** * set the corresponding message for the specified Property of all the object in List * @param objList - the list of object/* ww w. ja va2 s . com*/ * @param protertyName - the target Property * @param value_msgKey - the value and the corresponding message's key in the Resource file * @param msgResources - MessageResources * @param request - http servlet request */ static public void setMsgInObj(List objList, String protertyName, HashMap value_msgKey, MessageResources msgResources, HttpServletRequest request) throws Exception { int objNumbers = objList.size(); Object object; Object objValue; for (int i = 0; i < objNumbers; i++) { object = objList.get(i); try { objValue = PropertyUtils.getProperty(object, protertyName); } catch (Exception e) { throw e; } if (value_msgKey.containsKey(objValue)) { //need change the value to the corresponding message PropertyUtils.setProperty(object, protertyName, msgResources.getMessage(request.getLocale(), (String) value_msgKey.get(objValue.toString()))); } } }
From source file:com.nerve.commons.repository.utils.ConvertUtils.java
/** * ????javaBean?javabeanproperties?/*from ww w. jav a 2 s. co m*/ * ?nametitle * javabeannamevalue * properties * { * name:name, * title:value * } * ?name?javabeannametitle?value * @param collection * @param properties * @return */ public static List convertElementPropertyToBeanList(final Collection collection, final Map<String, String> properties, Class<?> toType) { List list = new ArrayList(); try { for (Object obj : collection) { Object bean = toType.newInstance(); for (String key : properties.keySet()) { PropertyUtils.setProperty(bean, properties.get(key), PropertyUtils.getProperty(obj, key)); } list.add(bean); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return list; }
From source file:com.mooing.wss.common.util.BeanUtil.java
/** * JavaBean/*w ww . j a v a2 s .c o m*/ * * @param bean JavaBean * @param property ?? * @param value * @throws PropertyAccessException */ public static void setBeanProperty(Object bean, String property, Object value) throws PropertyAccessException { try { // PropertyUtils.setProperty(bean, property, value); } catch (IllegalArgumentException e) { throw new PropertyAccessException(e); } catch (IllegalAccessException e) { throw new PropertyAccessException(e); } catch (InvocationTargetException e) { throw new PropertyAccessException(e.getTargetException()); } catch (NoSuchMethodException e) { throw new PropertyAccessException(e); } }
From source file:net.sf.json.TestJSONObjectStaticBuilders_ObjectBean.java
protected Object getSource() { ObjectBean bean = new ObjectBean(); String[] props = getProperties(); try {//w w w . jav a 2 s.c o m for (int i = 0; i < props.length; i++) { PropertyUtils.setProperty(bean, props[i], PropertyConstants.getPropertyValue(props[i])); } } catch (Exception e) { throw new RuntimeException(e); } return bean; }