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:com.esofthead.mycollab.schedule.email.format.DateFieldFormat.java
@Override public String formatField(MailContext<?> context) { Object wrappedBean = context.getWrappedBean(); Object value;//from w w w . j av a 2 s .c o m try { value = PropertyUtils.getProperty(wrappedBean, fieldName); if (value == null) { return new Span().write(); } else { return new Span().appendText(DateTimeUtils.formatDate((Date) value, LocaleHelper.getDateFormatAssociateToLocale(context.getLocale()), TimezoneMapper.getTimezone(context.getUser().getTimezone()))).write(); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error("Can not generate email field: " + fieldName, e); return new Span().write(); } }
From source file:com.tonbeller.wcf.tree.TreeHandler.java
public void initialize(RequestContext context, XmlComponent xmlComp, Element element) throws Exception { super.initialize(context, xmlComp, element); // must access the bean, so it has to be a FormComponent formComp = (FormComponent) xmlComp;// w w w . jav a2s. c om String ref = XoplonCtrl.getModelReference(element); Object bean = formComp.getBean(); TreeModel tm = (TreeModel) PropertyUtils.getProperty(bean, ref); tree = new TreeComponent(element.getAttribute("id"), formComp, tm); DefaultSelectionModel dsm = new DefaultSelectionModel(); String selmode = element.getAttribute("selmode"); if ("href".equals(selmode)) dsm.setMode(SelectionModel.SINGLE_SELECTION_HREF); else if ("single".equals(selmode)) dsm.setMode(SelectionModel.SINGLE_SELECTION); else if ("multi".equals(selmode)) dsm.setMode(SelectionModel.MULTIPLE_SELECTION); else if ("button".equals(selmode)) dsm.setMode(SelectionModel.MULTIPLE_SELECTION_BUTTON); else dsm.setMode(SelectionModel.NO_SELECTION); tree.setSelectionModel(dsm); if (tm instanceof SelectionChangeListener) dsm.addSelectionListener((SelectionChangeListener) tm); // override border by setting an attribute String border = element.getAttribute("border"); if (border.length() > 0) tree.setBorder(border); // override width by setting an attribute String width = element.getAttribute("width"); if (width.length() > 0) tree.setWidth(width); // override renderId Attribute always tree.setRenderId(element.getAttribute("id")); // click in tree should validate the user input in form fields tree.addFormListener(formComp); formComp.addFormListener(tree); tree.initialize(context); }
From source file:com.mycollab.mobile.module.crm.ui.RelatedReadItemField.java
@Override protected Component initContent() { try {/*from w w w . j a v a 2 s.c om*/ final String type = (String) PropertyUtils.getProperty(RelatedReadItemField.this.bean, "type"); if (type == null || type.equals("")) { return new Label(""); } final Integer typeid = (Integer) PropertyUtils.getProperty(bean, "typeid"); if (typeid == null) { return new Label(""); } Resource relatedLink = null; String relateItemName = null; if ("Account".equals(type)) { AccountService accountService = AppContextUtil.getSpringBean(AccountService.class); final SimpleAccount account = accountService.findById(typeid, MyCollabUI.getAccountId()); if (account != null) { relateItemName = account.getAccountname(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/account.png")); } } else if ("Campaign".equals(type)) { CampaignService campaignService = AppContextUtil.getSpringBean(CampaignService.class); final SimpleCampaign campaign = campaignService.findById(typeid, MyCollabUI.getAccountId()); if (campaign != null) { relateItemName = campaign.getCampaignname(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/campaign.png")); } } else if ("Contact".equals(type)) { ContactService contactService = AppContextUtil.getSpringBean(ContactService.class); final SimpleContact contact = contactService.findById(typeid, MyCollabUI.getAccountId()); if (contact != null) { relateItemName = contact.getContactName(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/contact.png")); } } else if ("Lead".equals(type)) { LeadService leadService = AppContextUtil.getSpringBean(LeadService.class); final SimpleLead lead = leadService.findById(typeid, MyCollabUI.getAccountId()); if (lead != null) { relateItemName = lead.getLeadName(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/lead.png")); } } else if ("Opportunity".equals(type)) { OpportunityService opportunityService = AppContextUtil.getSpringBean(OpportunityService.class); final SimpleOpportunity opportunity = opportunityService.findById(typeid, MyCollabUI.getAccountId()); if (opportunity != null) { relateItemName = opportunity.getOpportunityname(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/opportunity.png")); } } else if ("Case".equals(type)) { CaseService caseService = AppContextUtil.getSpringBean(CaseService.class); final SimpleCase cases = caseService.findById(typeid, MyCollabUI.getAccountId()); if (cases != null) { relateItemName = cases.getSubject(); relatedLink = new ExternalResource( StorageFactory.generateAssetRelativeLink("icons/16/crm/case.png")); } } Button related = new Button(relateItemName); if (relatedLink != null) related.setIcon(relatedLink); if (relatedLink != null) { return related; } else { return new Label(""); } } catch (Exception e) { return new Label(""); } }
From source file:com.framework.infrastructure.utils.HibernateUtils.java
/** * ID,./*w w w . ja v a 2 s .co m*/ * * id,id. * id,id. ID, * cascade-save-or-update. * * @param srcObjects * ,. * @param checkedIds * ,ID. * @param clazz * * @param idName * */ public static <T, ID> void mergeByCheckedIds(final Collection<T> srcObjects, final Collection<ID> checkedIds, final Class<T> clazz, final String idName) { // Assert.notNull(srcObjects, "scrObjects"); Assert.hasText(idName, "idName"); Assert.notNull(clazz, "clazz"); // , . if (checkedIds == null) { srcObjects.clear(); return; } // ,idID,. // ,id,idid. Iterator<T> srcIterator = srcObjects.iterator(); try { while (srcIterator.hasNext()) { T element = srcIterator.next(); Object id; id = PropertyUtils.getProperty(element, idName); if (!checkedIds.contains(id)) { srcIterator.remove(); } else { checkedIds.remove(id); } } // IDid,,id. for (ID id : checkedIds) { T obj = clazz.newInstance(); PropertyUtils.setProperty(obj, idName, id); srcObjects.add(obj); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } }
From source file:com.clican.pluto.common.util.SearchUtils.java
/** * ????//from w w w . j a v a 2s. c o m * * @param <T> * * @param <K> * * @param source * ? * @param comparablePropName * ? * @param comp * * @return */ @SuppressWarnings("unchecked") public static <T, K> T searchPreviousNearestInput(List<T> source, String comparablePropName, Comparable<K> comp) { if (source == null || source.size() == 0) { return null; } for (int i = (source.size() - 1); i >= 0; i--) { T input = source.get(i); try { K value = (K) PropertyUtils.getProperty(input, comparablePropName); if (comp.compareTo(value) >= 0) { return input; } } catch (Exception e) { throw new RuntimeException(e); } } return null; }
From source file:com.esofthead.mycollab.schedule.email.format.CurrencyFieldFormat.java
@Override public String formatField(MailContext<?> context) { Object wrappedBean = context.getWrappedBean(); Object value;/*from w w w . j a v a2 s. c o m*/ try { value = PropertyUtils.getProperty(wrappedBean, fieldName); if (value == null) { return new Span().write(); } else if (value instanceof Currency) { return new Span().appendText(((Currency) value).getSymbol()).write(); } else { CurrencyService currencyService = ApplicationContextUtil.getSpringBean(CurrencyService.class); Currency currency = currencyService.getCurrency((Integer) value); return new Span().appendText(currency.getSymbol()).write(); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error("Can not generate email field: " + fieldName, e); return new Span().write(); } }
From source file:com.esofthead.mycollab.schedule.email.format.DateTimeFieldFormat.java
@Override public String formatField(MailContext<?> context) { Object wrappedBean = context.getWrappedBean(); Object value;//from w w w. ja v a2 s . c o m try { value = PropertyUtils.getProperty(wrappedBean, fieldName); if (value == null) { return new Span().write(); } else { return new Span().appendText(DateTimeUtils.formatDate((Date) value, LocaleHelper.getDateTimeFormatAssociateToLocale(context.getLocale()), TimezoneMapper.getTimezone(context.getUser().getTimezone()))).write(); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { log.error("Can not generate email field: " + fieldName, e); return new Span().write(); } }
From source file:com.nec.nsgui.action.cifs.CommonUtil.java
static public void setNoContentMsgInObj(Object obj, String protertyName, MessageResources msgResources, HttpServletRequest request) throws Exception { Object objValue;/*from ww w . j a v a 2 s. c o m*/ try { objValue = PropertyUtils.getProperty(obj, protertyName); } catch (Exception e) { throw e; } if (objValue.toString().equals("")) { PropertyUtils.setProperty(obj, protertyName, msgResources.getMessage(request.getLocale(), "cifs.shareDetial.nocontent")); } }
From source file:com.lioland.harmony.services.dao.ODBClass.java
public void loadObject() { Class cls = this.getClass(); try {//from w ww .j a va 2s .co m String query = "select * from " + cls.getSimpleName() + " where " + getUniqueFieldName() + "='" + PropertyUtils.getProperty(this, getUniqueFieldName()) + "'"; System.out.println("Query: " + query); List<ODocument> docs = DBFactory.getInstance().getDb().query(new OSQLSynchQuery<ODocument>(query)); if (!docs.isEmpty()) { fillObject(docs.get(0), this); } } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException ex) { Logger.getLogger(ODBClass.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:corner.orm.tapestry.component.CornerSelectModel.java
/** * cnlabelField//from w ww . ja v a 2 s . c om * @param value * @return */ public String getCnLabelFor(Object value) { try { if (value instanceof String) { return value.toString(); } else { return PropertyUtils .getProperty(value, TapestryHtmlFormatter.lowerFirstLetter(this.filter.getCnLabel())) .toString(); } } catch (Exception e) { throw new ApplicationRuntimeException(e); } }