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.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java
@Override public void undo() { if (encendido && activo) { try {/*from w w w . ja v a2s. c o m*/ if (this.data.emptyUndo()) { LOGGER.debug(getClass().getSimpleName() + " undo vacio"); return; } EditorLog log = this.data.popUndo(); currentUndo = log; PropertyUtils.setProperty(log.getTarget(), log.getProperty(), log.getValue()); currentUndo = null; } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { EditorMonitorImpV3.LOGGER.error(ex); } } }
From source file:com.easyget.commons.csv.bean.CsvToBean.java
/** * Creates a single object from a line from the csv file. * @param mapper - MappingStrategy//from www. j ava 2 s .c om * @param line - array of Strings from the csv file. * @return - object containing the values. * @throws IllegalAccessException - thrown on error creating bean. * @throws InvocationTargetException - thrown on error calling the setters. * @throws InstantiationException - thrown on error creating bean. * @throws IntrospectionException - thrown on error getting the PropertyDescriptor. * @throws ParseException */ protected T processLine(MappingStrategy<T> mapper, Line line, FieldFormater formater) throws IllegalAccessException, InvocationTargetException, InstantiationException, IntrospectionException, ParseException { T bean = mapper.createBean(); String[] fields = line.getLine(); for (int col = 0; col < fields.length; col++) { PropertyDescriptor prop = mapper.findDescriptor(col); String value = checkForTrim(fields[col], prop); // ? if (formater != null) value = formater.parse(value); try { Class<?> clazz = prop.getPropertyType(); Object ov = ConvertUtils.convert(value, clazz); PropertyUtils.setProperty(bean, prop.getName(), ov); } catch (NoSuchMethodException e) { // } } return bean; }
From source file:com.feilong.core.bean.BeanUtilTest.java
/** * Demo normal java beans.//www. j a va 2 s . c om * * @throws Exception * the exception */ @Test public void testDemoNormalJavaBeans() throws Exception { LOGGER.debug(StringUtils.center(" demoNormalJavaBeans ", 40, "=")); // data setup Customer customer = new Customer(123, "John Smith", toArray(new Address("CA1234", "xxx", "Los Angeles", "USA"), new Address("100000", "xxx", "Beijing", "China"))); // accessing the city of first address String name = (String) PropertyUtils.getSimpleProperty(customer, "name"); String city = (String) PropertyUtils.getProperty(customer, "addresses[0].city"); LOGGER.debug(StringUtils .join(new Object[] { "The city of customer ", name, "'s first address is ", city, "." })); // setting the zipcode of customer's second address String zipPattern = "addresses[1].zipCode"; if (PropertyUtils.isWriteable(customer, zipPattern)) {//PropertyUtils LOGGER.debug("Setting zipcode ..."); PropertyUtils.setProperty(customer, zipPattern, "200000");//PropertyUtils } String zip = (String) PropertyUtils.getProperty(customer, zipPattern);//PropertyUtils LOGGER.debug(StringUtils .join(new Object[] { "The zipcode of customer ", name, "'s second address is now ", zip, "." })); }
From source file:com.expressui.core.view.tomanyrelationship.AggregationRelationship.java
/** * Invoked when user confirms that she really wants to remove values. * * @param values values to be removed/* w ww.jav a2 s. com*/ */ public void removeConfirmed(T... values) { for (T value : values) { value = genericDao.getReference(value); preRemove(value); try { PropertyUtils.setProperty(value, getParentPropertyId(), null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } if (getEntityDao() == null) { genericDao.persist(value); } else { getEntityDao().persist(value); } } showRemoveSuccessful(); searchImpl(false); clearSelection(); syncCrudActions(); }
From source file:com.tikal.tallerWeb.servicio.monitor.imp.EditorMonitorImpV3.java
@Override public void redo() { if (encendido && activo) { try {/* ww w .j a v a 2s . c o m*/ if (this.data.emptyRedo()) { LOGGER.debug(getClass().getSimpleName() + " redo vacio"); return; } EditorLog log = this.data.popRedo(); currentRedo = log; PropertyUtils.setProperty(log.getTarget(), log.getProperty(), log.getValue()); currentRedo = null; } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { EditorMonitorImpV3.LOGGER.error(ex); } } }
From source file:com.esofthead.mycollab.mobile.module.crm.view.activity.RelatedItemSelectionField.java
@Override public void fireValueChange(Object data) { try {/*www . j a v a 2 s .c o m*/ Object dataId = PropertyUtils.getProperty(data, "id"); if (dataId == null) { PropertyUtils.setProperty(bean, "type", null); return; } setInternalValue((Integer) dataId); if (data instanceof SimpleAccount) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.ACCOUNT); navButton.setCaption(((SimpleAccount) data).getAccountname()); } else if (data instanceof SimpleCampaign) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.CAMPAIGN); navButton.setCaption(((SimpleCampaign) data).getCampaignname()); } else if (data instanceof SimpleContact) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.CONTACT); navButton.setCaption(((SimpleContact) data).getContactName()); } else if (data instanceof SimpleLead) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.LEAD); navButton.setCaption(((SimpleLead) data).getLeadName()); } else if (data instanceof SimpleOpportunity) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.OPPORTUNITY); navButton.setCaption(((SimpleOpportunity) data).getOpportunityname()); } else if (data instanceof SimpleCase) { PropertyUtils.setProperty(bean, "type", CrmTypeConstants.CASE); navButton.setCaption(((SimpleCase) data).getSubject()); } } catch (Exception e) { LOG.error("Error when fire value", e); } }
From source file:jp.co.opentone.bsol.linkbinder.dao.BaseDao.java
/** * ???.//from ww w. j a va2 s . c o m * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ private void escape(Object clone, List<String> fields) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { String escapeChar = (String) PropertyUtils.getProperty(clone, "escapeChar"); String escapeEscapeChar = escapeChar + escapeChar; String escapePercent = escapeChar + PERCENT; String escapeUnderBar = escapeChar + UNDER_BAR; for (String field : fields) { Object object = PropertyUtils.getProperty(clone, field); if (object != null) { String value = String.valueOf(object); // ? value = value.replaceAll(escapeChar, escapeEscapeChar); // %? value = value.replaceAll(PERCENT, escapePercent); // _? value = value.replaceAll(UNDER_BAR, escapeUnderBar); PropertyUtils.setProperty(clone, field, value); } } }
From source file:at.molindo.notify.model.BeanParams.java
private void setProperty(Param<?> param, Object value) { PropertyDescriptor pd = getDescriptor(param.getName()); if (pd == null) { // TODO simply ignore? return;// w w w. ja v a2 s. c o m } Object converted; if (value == null || pd.getPropertyType().isAssignableFrom(value.getClass())) { converted = value; } else { converted = Param.p(pd.getPropertyType(), pd.getName()).toObject(param.toString(value)); } try { PropertyUtils.setProperty(_bean, param.getName(), converted); } catch (NoSuchMethodException e) { throw new NotifyRuntimeException(e); } catch (IllegalAccessException e) { throw new NotifyRuntimeException(e); } catch (InvocationTargetException e) { throw new NotifyRuntimeException(e); } }
From source file:com.jk.util.JKObjectUtil.java
/** * Sets the peoperty value./*from www.j a v a 2 s . c o m*/ * * @param source * the source * @param fieldName * the field name * @param value * the value */ public static void setPeopertyValue(final Object source, final String fieldName, final Object value) { try { PropertyUtils.setProperty(source, fieldName, value); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); } }
From source file:com.expressui.core.view.field.SelectField.java
/** * Listener method invoked when user selects item. *//*from w ww . j a v a 2s . com*/ public void itemSelected() { V selectedValue = getSelectedValue(); V reFoundEntity = genericDao.reFind(selectedValue); if (reFoundEntity == null) { throw new EntityNotFoundException(selectedValue.toString()); } T bean = typedForm.getBean(); try { PropertyUtils.setProperty(bean, propertyId, selectedValue); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } Property property = field.getPropertyDataSource(); field.setPropertyDataSource(property); entitySelect.close(); }