List of usage examples for org.springframework.beans BeanWrapper getPropertyValue
@Nullable
Object getPropertyValue(String propertyName) throws BeansException;
From source file:am.ik.categolj2.infra.codelist.MethodInvokingCodeList.java
@Override protected Map<String, String> retrieveMap() { try {//from w w w .j a v a 2 s.c om methodInvoker.prepare(); List<?> targetList = (List<?>) methodInvoker.invoke(); Map<String, String> map = new LinkedHashMap<>(); for (Object target : targetList) { BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(target); Object valueObject = beanWrapper.getPropertyValue(valueField); Object labelObject = beanWrapper.getPropertyValue(labelField); String value = conversionService.convert(valueObject, String.class); String label = conversionService.convert(labelObject, String.class); map.put(value, label); } return map; } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:com.github.javarch.jsf.SelectItemsUtils.java
/** * Dada uma Lista de objetos cria uma lista de SelectItem onde o valor ser * uma chamada ao mtodo get do atributo <i>idProperty</i> e o valor o retorno * do mtodo get da propriedade <i>labelProperty</i>. * * Esse mtodo adiciona um item para indicar a necessidade de seleo do item definido * no parmetro labelOptional// www . j a v a 2s.c o m * * * @param list - Lista de objetos que devem construir a lista de select items. * @param idProperty - propriedade que define o valor das chaves do select item. * @param labelProperty - pripriedade que define o rtulo do select item * @param labelOptional - Rtulo do primeiro item do select item que define a necessidade de seleo de um item. * @return Uma lista de objetos select item. */ public List<SelectItem> createSelectItems(final List iter, String idProperty, String labelProperty, String labelOptional) { List<SelectItem> selectItems = new ArrayList<SelectItem>(); if (iter == null) { return selectItems; } if (labelOptional != null) { selectItems.add(new SelectItem(null, labelOptional)); } Iterator it = iter.iterator(); while (it.hasNext()) { Object item = (Object) it.next(); String label; String id; try { BeanWrapper entity = new BeanWrapperImpl(item); label = "" + entity.getPropertyValue(labelProperty); id = entity.getPropertyValue(idProperty).toString(); } catch (Exception ex) { label = "???" + labelProperty + "???"; id = "???" + idProperty + "???"; } SelectItem selectItem = new SelectItem(id, label); selectItems.add(selectItem); } return selectItems; }
From source file:nl.tue.gale.common.SpringManipulator.java
public <E> void setList(List<E> list) { BeanWrapper wrapper = new BeanWrapperImpl(bean); @SuppressWarnings("unchecked") List<E> beanList = new ArrayList<E>((List<E>) wrapper.getPropertyValue(property)); beanList.addAll(list);/*from w w w .j av a 2 s . c o m*/ wrapper.setPropertyValue(property, beanList); }
From source file:egov.data.hibernate.repository.support.HibernateMetamodelEntityInformation.java
@Override public ID getId(T entity) { BeanWrapper entityWrapper = new DirectFieldAccessFallbackBeanWrapper(entity); return (ID) entityWrapper.getPropertyValue(idProperty); }
From source file:org.jdal.swing.action.ComboLinker.java
/** * {@inheritDoc}// w w w .j a v a 2 s . c om * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @SuppressWarnings("unchecked") public void actionPerformed(ActionEvent e) { Object selected = primary.getSelectedItem(); if (selected != null) { BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(selected); Collection<Object> collection = (Collection<Object>) wrapper.getPropertyValue(propertyName); DefaultComboBoxModel model = new DefaultComboBoxModel(new Vector<Object>(collection)); dependent.setModel(model); } }
From source file:nl.tue.gale.common.SpringManipulator.java
public <K, V> void setMap(Map<K, V> map) { BeanWrapper wrapper = new BeanWrapperImpl(bean); @SuppressWarnings("unchecked") Map<K, V> beanMap = new HashMap<K, V>((Map<K, V>) wrapper.getPropertyValue(property)); beanMap.putAll(map);/*from w w w . j ava 2 s . co m*/ wrapper.setPropertyValue(property, beanMap); }
From source file:org.lightadmin.core.storage.strategy.file.ReferenceFilePathResolver.java
private Object getPropertyValue(Object entity, PersistentProperty persistentProperty) { BeanWrapper beanWrapper = new DirectFieldAccessFallbackBeanWrapper(entity); return beanWrapper.getPropertyValue(persistentProperty.getName()); }
From source file:cz.clovekvtisni.coordinator.server.validation.constraints.impl.EqualPropertiesValidator.java
@Override public boolean isValid(Object bean, ConstraintValidatorContext context) { Object prevValue = null;/*from w ww . j av a2s .c o m*/ BeanWrapper beanWrapper = new BeanWrapperImpl(bean); for (int i = 0, l = annotation.properties().length; i < l; i++) { Object value = beanWrapper.getPropertyValue(annotation.properties()[i]); if (i == 0) { prevValue = value; } else { if (value == null && prevValue != null || value != null && !value.equals(prevValue)) { context.buildConstraintViolationWithTemplate(annotation.message()) .addNode(annotation.properties()[0]).addConstraintViolation() .disableDefaultConstraintViolation(); return false; } } } return true; }
From source file:com.example.securelogin.app.common.validation.NotReusedPasswordValidator.java
@Override public boolean isValid(Object value, ConstraintValidatorContext context) { BeanWrapper beanWrapper = new BeanWrapperImpl(value); String username = (String) beanWrapper.getPropertyValue(usernamePropertyName); String newPassword = (String) beanWrapper.getPropertyValue(newPasswordPropertyName); Account account = accountSharedService.findOne(username); String currentPassword = account.getPassword(); boolean result = checkNewPasswordDifferentFromCurrentPassword(newPassword, currentPassword, context); if (result && account.getRoles().contains(Role.ADMIN)) { result = checkHistoricalPassword(username, newPassword, context); }/*from w ww . ja v a 2s .c o m*/ return result; }
From source file:uk.co.blackpepper.support.retrofit.jsoup.spring.AbstractBeanHtmlConverter.java
private String getAsText(Object bean, String propertyName) { BeanWrapper beanWrapper = wrap(bean); Object value = beanWrapper.getPropertyValue(propertyName); TypeDescriptor typeDescriptor = beanWrapper.getPropertyTypeDescriptor(propertyName); return (String) conversionService.convert(value, typeDescriptor, TypeDescriptor.valueOf(String.class)); }