List of usage examples for org.apache.commons.beanutils PropertyUtils getNestedProperty
public static Object getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:org.charleech.primefaces.eval.ui.table.lazy.LazySorter.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from w w w .j a v a2s . com public int compare(final MyData data1, final MyData data2) { try { final Object value1 = PropertyUtils.getNestedProperty(data1, this.sortField); final Object value2 = PropertyUtils.getNestedProperty(data2, this.sortField); final int value = ((Comparable) value1).compareTo(value2); return SortOrder.ASCENDING.equals(this.sortOrder) ? value : -1 * value; } catch (final Exception e) { throw new RuntimeException(e); } }
From source file:org.fornax.cartridges.sculptor.framework.propertyeditor.OptionEditor.java
/** * Format the Object as String of concatenated properties. *//*from ww w .j av a2 s . com*/ public String getAsText() { Object value = getValue(); if (value == null) { return ""; } String propertyName = null; // used in error handling below try { StringBuffer label = new StringBuffer(); for (int i = 0; i < properties.length; i++) { propertyName = properties[i]; Class<?> propertyType = PropertyUtils.getPropertyType(value, propertyName); Object propertyValue = PropertyUtils.getNestedProperty(value, propertyName); PropertyEditor editor = registry.findCustomEditor(propertyType, registryPropertyNamePrefix + propertyName); if (editor == null) { label.append(propertyValue); } else { editor.setValue(propertyValue); label.append(editor.getAsText()); editor.setValue(null); } if (i < (properties.length - 1)) { label.append(separator); } } return label.toString(); } catch (Exception e) { throw new IllegalArgumentException("Couldn't access " + propertyName + " of " + value.getClass().getName() + " : " + e.getMessage(), e); } }
From source file:org.geoserver.jdbcconfig.internal.InfoIdentities.java
public final <T extends Info> List<InfoIdentity> getIdentities(T info) { Class<? extends Info> rootClazz = root(info.getClass()); if (rootClazz == null) { return Collections.emptyList(); } else {//from ww w .ja v a 2 s . c o m List<InfoIdentity> list = new ArrayList<>(); for (String[] descriptor : descriptors.get(rootClazz)) { String[] idValues = new String[descriptor.length]; for (int i = 0; i < descriptor.length; i++) { try { idValues[i] = PropertyUtils.getNestedProperty(info, descriptor[i]).toString(); } catch (NestedNullException e) { idValues[i] = null; } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IllegalStateException(e); } } list.add(new InfoIdentity(rootClazz, descriptor, idValues)); } return list; } }
From source file:org.gvnix.datatables.tags.RooTableTag.java
/** * Gets Id content//from w w w.j a va 2 s .c o m * * @return * @throws JspException */ protected String getIdContent() throws JspException { ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser.parseExpression(this.rowIdBase); EvaluationContext context = new StandardEvaluationContext(currentObject); Object value = exp.getValue(context); String result = ""; if (value == null) { // Use AbstractTablaTag standard behavior try { value = PropertyUtils.getNestedProperty(this.currentObject, this.rowIdBase); } catch (IllegalAccessException e) { LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase); throw new JspException(e); } catch (InvocationTargetException e) { LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase); throw new JspException(e); } catch (NoSuchMethodException e) { LOGGER.error("Unable to get the value for the given rowIdBase {}", this.rowIdBase); throw new JspException(e); } } if (value != null) { // TODO manage exceptions to log it ConversionService conversionService = (ConversionService) helper.getBean(this.pageContext, getConversionServiceId()); if (conversionService != null && conversionService.canConvert(value.getClass(), String.class)) { result = conversionService.convert(value, String.class); } else { result = ObjectUtils.getDisplayString(value); } result = HtmlUtils.htmlEscape(result); } return result; }
From source file:org.jahia.services.uicomponents.bean.toolbar.Item.java
private void addToParent(Object o) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { if (o instanceof String) { String parentPath = (String) o; String beanId = StringUtils.substringBefore(parentPath, "."); Object bean = SpringContextSingleton.getBean(beanId); String propertyPath = StringUtils.substringAfter(parentPath, "."); if (propertyPath.length() > 0) { bean = PropertyUtils.getNestedProperty(bean, propertyPath); }/*w w w.j a v a2s .co m*/ if (bean == null) { throw new IllegalArgumentException("Unable to find target for parent path: " + parentPath); } if (!(bean instanceof Menu || bean instanceof Toolbar)) { throw new IllegalArgumentException("Target bean for path '" + parentPath + "' is not of type Menu or Toolbar. Unable to handle beans of type '" + bean.getClass().getName() + "'"); } o = bean; } if (o instanceof Menu) { Menu parentMenu = (Menu) o; parentMenu.removeItem(getId()); int index = -1; if (position >= 0) { index = position; } else if (positionBefore != null) { index = parentMenu.getItems().indexOf(new Item(positionBefore)); } else if (positionAfter != null) { index = parentMenu.getItems().indexOf(new Item(positionAfter)); if (index != -1) { index++; } if (index >= parentMenu.getItems().size()) { index = -1; } } if (index != -1) { parentMenu.addItem(index, this); } else { parentMenu.addItem(this); } } else if (o instanceof Toolbar) { Toolbar parentToolbar = (Toolbar) o; parentToolbar.removeItem(getId()); int index = -1; if (position >= 0) { index = position; } else if (positionBefore != null) { index = parentToolbar.getItems().indexOf(new Item(positionBefore)); } else if (positionAfter != null) { index = parentToolbar.getItems().indexOf(new Item(positionAfter)); if (index != -1) { index++; } if (index >= parentToolbar.getItems().size()) { index = -1; } } if (index != -1) { parentToolbar.addItem(index, this); } else { parentToolbar.addItem(this); } } else { throw new IllegalArgumentException( "Unknown parent type '" + o.getClass().getName() + "'. Can accept Menu, Toolbar or" + " a String value with a bean-compliant path to the corresponding menu/toobar bean"); } }
From source file:org.jpos.ee.pm.core.PresentationManager.java
/**Getter for an object property value * @param obj The object//from w w w.jav a 2 s . co m * @param propertyName The property * @return The value of the property of the object * */ public Object get(Object obj, String propertyName) { try { if (obj != null && propertyName != null) { return PropertyUtils.getNestedProperty(obj, propertyName); } } catch (NullPointerException e) { // OK to happen } catch (NestedNullException e) { // Hmm... that's fine too } catch (Exception e) { // Now I don't like it. error(e); return "-undefined-"; } return null; }
From source file:org.kuali.coeus.org.kuali.rice.krad.uif.element.CollectionToggleMenu.java
protected String getActionLabel(Object obj) { try {/*from www.j a va2 s . c o m*/ return PropertyUtils.getNestedProperty(obj, this.getActionLabelPropertyName()).toString(); } catch (Exception e) { LOG.error("Problem creating actionLabel from actionLabelPropertyName", e); } return null; }
From source file:org.kuali.coeus.propdev.impl.abstrct.AbstractTypeValuesFinder.java
private String getFieldValue(ViewModel model, InputField field) { if (!StringUtils.startsWith(field.getBindingInfo().getBindingPath(), "new")) { try {/* w w w . ja v a 2 s.co m*/ return (String) PropertyUtils.getNestedProperty(model, field.getBindingInfo().getBindingPath()); } catch (Exception e) { throw new RuntimeException("could not retrieve abstract type from the input field", e); } } return StringUtils.EMPTY; }
From source file:org.kuali.coeus.propdev.impl.attachment.ProposalDevelopmentAttachmentController.java
@Transactional @RequestMapping(value = "/proposalDevelopment", params = "methodToCall=updateEditableFileAttachment") public ModelAndView updateEditableFileAttachment( @ModelAttribute("KualiForm") ProposalDevelopmentDocumentForm form) throws Exception { String collectionPath = form.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH); String selectedLine = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService()).toggleAttachmentFile(form, collectionPath, selectedLine); List<ProposalDevelopmentAttachment> attachments = (List<ProposalDevelopmentAttachment>) PropertyUtils .getNestedProperty(form, collectionPath); attachments.get(Integer.parseInt(selectedLine)).setMultipartFile(null); return getRefreshControllerService().refresh(form); }
From source file:org.kuali.coeus.propdev.impl.attachment.ProposalDevelopmentAttachmentController.java
@Transactional @RequestMapping(value = "/proposalDevelopment", params = "methodToCall=updateEditableProposalFileAttachment") public ModelAndView updateEditableProposalFileAttachment( @ModelAttribute("KualiForm") ProposalDevelopmentDocumentForm form) throws Exception { String collectionPath = ProposalDevelopmentConstants.PropertyConstants.NARRATIVES; String selectedLine = form.getProposalDevelopmentAttachmentHelper().getSelectedLineIndex(); ((ProposalDevelopmentViewHelperServiceImpl) form.getViewHelperService()).toggleAttachmentFile(form, ProposalDevelopmentConstants.PropertyConstants.NARRATIVES, form.getProposalDevelopmentAttachmentHelper().getSelectedLineIndex()); List<ProposalDevelopmentAttachment> attachments = (List<ProposalDevelopmentAttachment>) PropertyUtils .getNestedProperty(form, collectionPath); attachments.get(Integer.parseInt(selectedLine)).setMultipartFile(null); return getRefreshControllerService().refresh(form); }