List of usage examples for org.apache.commons.beanutils PropertyUtils getProperty
public static Object getProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return 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:jetx.ext.springsecurity.SpringSecurityTags.java
public static void principal(JetTagContext ctx, String property) throws IOException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { Object principal = authentication.getPrincipal(); if (principal != null) { try { String val = PropertyUtils.getProperty(principal, property).toString(); ctx.getWriter().print(val); } catch (Exception e) { // }/* w w w.j a v a 2s . co m*/ } } }
From source file:info.magnolia.cms.gui.controlx.list.util.ValueProvider.java
/** * get value - first check for property in this object - then look for the getter for this name - else search in * MetaData/* ww w. j av a2 s . c o m*/ * @param name * @param obj */ public Object getValue(String name, Object obj) { Object value = null; try { if (obj instanceof Content) { Content node = (Content) obj; if (node.hasNodeData(name)) { NodeData nd = node.getNodeData(name); if (nd.getType() == PropertyType.DATE) { value = nd.getDate(); } else { value = nd.getString(); } } if (value == null) { try { value = PropertyUtils.getProperty(node.getMetaData(), name); } catch (NoSuchMethodException e) { value = node.getMetaData().getStringProperty(name); if (StringUtils.isEmpty((String) value)) { value = null; } } } } if (value == null) { // is this a property of the object try { value = PropertyUtils.getProperty(obj, name); } catch (NoSuchMethodException e1) { // check if getter exist for this name try { String methodName = "get" + StringUtils.substring(name, 0, 1).toUpperCase() + StringUtils.substring(name, 1); value = MethodUtils.invokeMethod(this, methodName, obj); } catch (NoSuchMethodException e2) { value = StringUtils.EMPTY; } } } } catch (Exception e) { log.error("can't get value", e); value = StringUtils.EMPTY; } if (value instanceof Calendar) { value = new Date(((Calendar) value).getTimeInMillis()); } return value; }
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 w w w . j a v a2 s.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.googlecode.jtiger.modules.ecside.table.callback.NullSafeBeanComparator.java
/** * Compare beans safely. Handles NestedNullException thrown by PropertyUtils * when the parent object is null// w w w .ja v a2 s.c o m */ public int compare(Object o1, Object o2) { if (property == null) { // use the object's compare since no property is specified return this.comparator.compare(o1, o2); } Object val1 = null, val2 = null; try { try { val1 = PropertyUtils.getProperty(o1, property); } catch (NestedNullException ignored) { } try { val2 = PropertyUtils.getProperty(o2, property); } catch (NestedNullException ignored) { } if (val1 == val2 || (val1 == null && val2 == null)) { return -1; } if (val1 == null) { return this.nullsAreHigh ? 1 : -1; } if (val2 == null) { return this.nullsAreHigh ? -1 : 1; } return this.comparator.compare(val1, val2); } catch (Exception e) { e.printStackTrace(); log.warn(e); return 0; } }
From source file:com.esofthead.mycollab.module.crm.ui.components.RelatedItemSelectionWindow.java
public RelatedItemSelectionWindow(String title, RelatedListComp2 relatedList) { super(title); center();//from w w w. j a va2 s . c o m bodyContent = new MVerticalLayout(); this.setContent(bodyContent); this.relatedListComp = relatedList; this.setModal(true); this.setResizable(false); initUI(); tableItem.addTableListener(new TableClickListener() { private static final long serialVersionUID = 1L; @SuppressWarnings("unchecked") @Override public void itemClick(TableClickEvent 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.esofthead.mycollab.module.crm.ui.components.PeopleInfoComp.java
public void displayEntryPeople(ValuedBean bean) { this.removeAllComponents(); this.withMargin(new MarginInfo(true, false, true, true)); Label peopleInfoHeader = new Label( FontAwesome.USER.getHtml() + " " + AppContext.getMessage(CrmCommonI18nEnum.SUB_INFO_PEOPLE), ContentMode.HTML);//from w w w. jav a 2s . c o m peopleInfoHeader.setStyleName("info-hdr"); this.addComponent(peopleInfoHeader); GridLayout layout = new GridLayout(2, 2); layout.setSpacing(true); layout.setWidth("100%"); layout.setMargin(new MarginInfo(false, false, false, true)); try { Label createdLbl = new Label(AppContext.getMessage(CrmCommonI18nEnum.ITEM_CREATED_PEOPLE)); createdLbl.setSizeUndefined(); layout.addComponent(createdLbl, 0, 0); String createdUserName = (String) PropertyUtils.getProperty(bean, "createduser"); String createdUserAvatarId = (String) PropertyUtils.getProperty(bean, "createdUserAvatarId"); String createdUserDisplayName = (String) PropertyUtils.getProperty(bean, "createdUserFullName"); UserLink createdUserLink = new UserLink(createdUserName, createdUserAvatarId, createdUserDisplayName); layout.addComponent(createdUserLink, 1, 0); layout.setColumnExpandRatio(1, 1.0f); Label assigneeLbl = new Label(AppContext.getMessage(CrmCommonI18nEnum.ITEM_ASSIGN_PEOPLE)); assigneeLbl.setSizeUndefined(); layout.addComponent(assigneeLbl, 0, 1); String assignUserName = (String) PropertyUtils.getProperty(bean, "assignuser"); String assignUserAvatarId = (String) PropertyUtils.getProperty(bean, "assignUserAvatarId"); String assignUserDisplayName = (String) PropertyUtils.getProperty(bean, "assignUserFullName"); UserLink assignUserLink = new UserLink(assignUserName, assignUserAvatarId, assignUserDisplayName); layout.addComponent(assignUserLink, 1, 1); } catch (Exception e) { LOG.error("Can not build user link {} ", BeanUtility.printBeanObj(bean)); } this.addComponent(layout); }
From source file:net.sf.launch4j.binding.OptListBinding.java
public void put(IValidatable bean) { try {/*from www .j a va2s . co m*/ boolean selected = "true".equals(BeanUtils.getProperty(bean, _stateProperty)); _button.setSelected(selected); _textArea.setEnabled(selected); String[] items = (String[]) PropertyUtils.getProperty(bean, _property); StringBuffer sb = new StringBuffer(); for (int i = 0; i < items.length; i++) { sb.append(items[i]); if (i < items.length - 1) { sb.append("\n"); } } _textArea.setText(sb.toString()); } catch (Exception e) { throw new BindingException(e); } }
From source file:io.lightlink.dao.mapping.MappingEntry.java
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; MappingEntry entry = (MappingEntry) o; if (className != null ? !className.equals(entry.className) : entry.className != null) return false; if (usedProperties != null ? !usedProperties.equals(entry.usedProperties) : entry.usedProperties != null) return false; try {/*from w w w . j a v a 2s . c o m*/ if (usedProperties != null) for (String property : usedProperties) { Object p1 = PropertyUtils.getProperty(object, property); Object p2 = PropertyUtils.getProperty(entry.getObject(), property); if (p1 != p2 && (p1 == null || p2 == null || !p1.equals(p2))) { return false; } } } catch (Exception e) { LOG.error(e.toString(), e); throw new RuntimeException(e); } return true; }
From source file:io.wcm.devops.conga.generator.util.AbstractConfigurableObjectTreeProcessor.java
private void resolveNestedObjects(Object object, ConfigurableProcessor<T> processor, T parentPayload) { if (object == null || object.getClass().isEnum()) { return;//w ww . j a v a2 s.com } try { Map<String, String> description = BeanUtils.describe(object); for (String propertyName : description.keySet()) { Object propertyValue = PropertyUtils.getProperty(object, propertyName); if (!StringUtils.equals(propertyName, "class")) { process(propertyValue, processor, parentPayload); } } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new RuntimeException("Unable to get bean properties from '" + object.getClass().getName() + "'.", ex); } }
From source file:com.ultrapower.eoms.common.plugin.ecside.table.callback.NullSafeBeanComparator.java
/** * Compare beans safely. Handles NestedNullException thrown by PropertyUtils * when the parent object is null// w w w . jav a 2 s. c om */ @Override public int compare(Object o1, Object o2) { if (property == null) { // use the object's compare since no property is specified return this.comparator.compare(o1, o2); } Object val1 = null, val2 = null; try { try { val1 = PropertyUtils.getProperty(o1, property); } catch (NestedNullException ignored) { } try { val2 = PropertyUtils.getProperty(o2, property); } catch (NestedNullException ignored) { } if (val1 == val2 || (val1 == null && val2 == null)) { return -1; } if (val1 == null) { return this.nullsAreHigh ? 1 : -1; } if (val2 == null) { return this.nullsAreHigh ? -1 : 1; } return this.comparator.compare(val1, val2); } catch (Exception e) { e.printStackTrace(); log.warn(e); return 0; } }