List of usage examples for org.springframework.beans PropertyAccessor NESTED_PROPERTY_SEPARATOR
String NESTED_PROPERTY_SEPARATOR
To view the source code for org.springframework.beans PropertyAccessor NESTED_PROPERTY_SEPARATOR.
Click Source Link
From source file:com.technologicaloddity.saha.util.AjaxPageRendererImpl.java
public String renderWithNestedModel(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response, String nestedModelAttributeName) { request.setAttribute(FormTag.MODEL_ATTRIBUTE_VARIABLE_NAME, nestedModelAttributeName); request.setAttribute(NestedPathTag.NESTED_PATH_VARIABLE_NAME, nestedModelAttributeName + PropertyAccessor.NESTED_PROPERTY_SEPARATOR); return render(modelAndView, request, response); }
From source file:org.shept.util.BeanUtilsExtended.java
/** * Find all occurrences of targetClass in targetObject. * Be careful. This stuff may be recursive ! * Should be improved to prevent endless recursive loops. * /*from w w w .j ava 2 s .c o m*/ * @param * @return * * @param targetObject * @param targetClass * @param nestedPath * @return * @throws Exception */ public static Map<String, ?> findNestedPaths(Object targetObject, Class<?> targetClass, String nestedPath, List<String> ignoreList, Set<Object> visited, int maxDepth) throws Exception { Assert.notNull(targetObject); Assert.notNull(targetClass); Assert.notNull(ignoreList); HashMap<String, Object> nestedPaths = new HashMap<String, Object>(); if (maxDepth <= 0) { return nestedPaths; } nestedPath = (nestedPath == null ? "" : nestedPath); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(targetObject); PropertyDescriptor[] props = bw.getPropertyDescriptors(); for (PropertyDescriptor pd : props) { Class<?> clazz = pd.getPropertyType(); if (clazz != null && !clazz.equals(Class.class) && !clazz.isAnnotation() && !clazz.isPrimitive()) { Object value = null; String pathName = pd.getName(); if (!ignoreList.contains(pathName)) { try { value = bw.getPropertyValue(pathName); } catch (Exception e) { } // ignore any exceptions here if (StringUtils.hasText(nestedPath)) { pathName = nestedPath + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + pathName; } // TODO break up this stuff into checking and excecution a la ReflectionUtils if (targetClass.isAssignableFrom(clazz)) { nestedPaths.put(pathName, value); } // exclude objects already visited from further inspection to prevent circular references // unfortunately this stuff isn't fool proof as there are ConcurrentModificationExceptions // when adding objects to the visited list if (value != null && !isInstanceVisited(visited, value)) { nestedPaths.putAll( findNestedPaths(value, targetClass, pathName, ignoreList, visited, maxDepth - 1)); } } } } return nestedPaths; }
From source file:org.jdal.dao.hibernate.HibernateDao.java
/** * Create Order from criteria and property path * @param criteria the hibernate criteria to apply order on * @param propertyPath the property path * @return Order /*from ww w . ja v a 2 s . c o m*/ */ protected Order createOrder(Criteria criteria, String propertyPath, boolean ascending) { Order order = null; if (propertyPath != null) { String sortProperty = PropertyUtils.getPropertyName(propertyPath); try { if (PropertyUtils.isNested(propertyPath)) { String aliasPropertyPath = PropertyUtils.getPath(propertyPath); // Need to create alias? String alias = HibernateUtils.findAliasForPropertyPath(criteria, propertyPath); if (alias == null) { alias = PropertyUtils.getPropertyName(aliasPropertyPath); criteria.createAlias(aliasPropertyPath, alias); } sortProperty = alias + PropertyUtils.PROPERTY_SEPARATOR + sortProperty; } else { // test if property is an entity class Type sortType = getClassMetadata().getPropertyType(propertyPath); if (sortType.isEntityType()) { // is entity, look for 'name' property String[] propertyNames = getClassMetadata(sortType.getReturnedClass()).getPropertyNames(); for (String name : propertyNames) { if ("name".equals(name)) { log.info("Found property name on persistent class: " + sortType.getName()); String newPath = propertyPath + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + "name"; return createOrder(criteria, newPath, ascending); } } } } if (log.isDebugEnabled()) log.debug("Setting order as: " + sortProperty); order = ascending ? Order.asc(sortProperty) : Order.desc(sortProperty); } catch (HibernateException he) { log.error("Cannot to create Order for property: " + sortProperty + " for " + getEntityClass().getSimpleName(), he); } } else { // add default order by id ClassMetadata metadata = getClassMetadata(); if (metadata != null) order = Order.asc(metadata.getIdentifierPropertyName()); } return order; }
From source file:org.hdiv.web.servlet.tags.form.FormTagHDIV.java
/** * Writes the opening part of the block '<code>form</code>' tag and exposes * the form object name in the {@link javax.servlet.jsp.PageContext}. * @param tagWriter the {@link TagWriter} to which the form content is to be written * @return {@link javax.servlet.jsp.tagext.Tag#EVAL_BODY_INCLUDE} */// w w w . j a v a 2s . co m @Override protected int writeTagContent(TagWriter tagWriter) throws JspException { this.tagWriter = tagWriter; tagWriter.startTag(FORM_TAG); writeDefaultAttributes(tagWriter); tagWriter.writeAttribute(ACTION_ATTRIBUTE, resolveAction()); writeOptionalAttribute(tagWriter, METHOD_ATTRIBUTE, isMethodBrowserSupported(getMethod()) ? getMethod() : DEFAULT_METHOD); writeOptionalAttribute(tagWriter, TARGET_ATTRIBUTE, getTarget()); writeOptionalAttribute(tagWriter, ENCTYPE_ATTRIBUTE, getEnctype()); writeOptionalAttribute(tagWriter, ACCEPT_CHARSET_ATTRIBUTE, getAcceptCharset()); writeOptionalAttribute(tagWriter, ONSUBMIT_ATTRIBUTE, getOnsubmit()); writeOptionalAttribute(tagWriter, ONRESET_ATTRIBUTE, getOnreset()); writeOptionalAttribute(tagWriter, AUTOCOMPLETE_ATTRIBUTE, getAutocomplete()); tagWriter.forceBlock(); if (!isMethodBrowserSupported(getMethod())) { String composedValue = dataComposer.compose(getMethodParameter(), getMethod(), false); tagWriter.startTag(INPUT_TAG); writeOptionalAttribute(tagWriter, TYPE_ATTRIBUTE, "hidden"); writeOptionalAttribute(tagWriter, NAME_ATTRIBUTE, getMethodParameter()); writeOptionalAttribute(tagWriter, VALUE_ATTRIBUTE, composedValue); tagWriter.endTag(); } // Expose the form object name for nested tags... String modelAttribute = resolveModelAttribute(); this.pageContext.setAttribute(MODEL_ATTRIBUTE_VARIABLE_NAME, modelAttribute, PageContext.REQUEST_SCOPE); this.pageContext.setAttribute(COMMAND_NAME_VARIABLE_NAME, modelAttribute, PageContext.REQUEST_SCOPE); // Save previous nestedPath value, build and expose current nestedPath value. // Use request scope to expose nestedPath to included pages too. this.previousNestedPath = (String) this.pageContext.getAttribute(NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); this.pageContext.setAttribute(NESTED_PATH_VARIABLE_NAME, modelAttribute + PropertyAccessor.NESTED_PROPERTY_SEPARATOR, PageContext.REQUEST_SCOPE); return EVAL_BODY_INCLUDE; }
From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java
public void initBinder(WebRequest request, ComponentDataBinder binder, String componentPath) { if (logger.isInfoEnabled()) { logger.info("Register custom binding initializers"); }//from w w w. ja v a2 s . co m // Locale dependent registry - we should improve that - use java.text.spi ? Locale locale = RequestContextUtils.getLocale(((ServletWebRequest) request).getRequest()); String format = formatResolver.resolveProperty(locale, DateTimeLocaleConstants.DATETIME_FORMAT_LONG); // register 'nullable' bean editors for all Strings within filter objects // This way empty fields will not be part of the search criteria Map<String, CommandWrapper> pathMap = Collections.emptyMap(); if (binder.getTarget() instanceof SubCommandProvider) { pathMap = ComponentUtils.getComponentPathMap((SubCommandProvider) binder.getTarget()); CommandWrapper wrapper = pathMap.get(componentPath); if (wrapper.getCommand() instanceof FilteredListHolder) { FilteredListHolder flh = (FilteredListHolder) wrapper.getCommand(); FilterDefinition filterDef = flh.getFilter(); String path = ComponentUtils.getPropertyPathPrefix(componentPath) + FilteredListHolder.FILTER_BINDING_NAME + PropertyAccessor.NESTED_PROPERTY_SEPARATOR; for (Field field : filterDef.getClass().getDeclaredFields()) { String propPath = path + field.getName(); if (field.getType().equals(String.class)) { binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true)); if (logger.isInfoEnabled()) { logger.info("Registered nullable StringEditor for " + propPath); } } else if (field.getType().equals(Calendar.class)) { format = formatResolver.resolveProperty(locale, DateTimeLocaleConstants.DATE_FORMAT_SHORT); binder.registerCustomEditor(Calendar.class, propPath, new CustomCalendarEditor(new SimpleDateFormat(format), true)); if (logger.isInfoEnabled()) { logger.info("Registered Calendar Editor for " + propPath); } } else { registerDependendEntities(binder, field.getType(), path + field.getName()); } } } } }
From source file:org.shept.org.springframework.web.bind.support.FilterBindingInitializer.java
private void registerDependendEntities(ComponentDataBinder binder, Class clazz, String path) { Object ann = AnnotationUtils.findAnnotation(clazz, Entity.class); if (ann == null) return;/*from w ww. ja v a 2 s. co m*/ for (Field field : clazz.getDeclaredFields()) { String propPath = path + PropertyAccessor.NESTED_PROPERTY_SEPARATOR + field.getName(); if (field.getType().equals(String.class)) { binder.registerCustomEditor(String.class, propPath, new StringTrimmerEditor(true)); if (logger.isInfoEnabled()) { logger.info("Registered nullable StringEditor for " + propPath); } } else { // here we need to prevent infinte recursions for example if a user contains a user contains a user ... Integer depth = StringUtils.countOccurrencesOf(path, PropertyAccessor.NESTED_PROPERTY_SEPARATOR); if (depth <= maxDepth) { registerDependendEntities(binder, field.getType(), propPath); } } } }
From source file:org.shept.org.springframework.web.servlet.mvc.delegation.ComponentUtils.java
/** * /*from ww w . ja v a 2 s . c o m*/ * @param * @return the prefixed path name and append always the NESTED_PROPERTY_SEPARATOR to the end * * @param path * @return */ public static String getPropertyPathPrefix(String pathName) { if (StringUtils.hasLength(pathName) && !pathName.endsWith(PropertyAccessor.NESTED_PROPERTY_SEPARATOR)) { pathName = pathName + PropertyAccessor.NESTED_PROPERTY_SEPARATOR; } return pathName; }