/** * Shorten the length of the property if to long for the data-base. No log message is produced. * The field must be declared with JPA annotations in the given class (clazz). For getting and * setting the property the getter and setter method is used. * * @param clazz The class where the field is declared. * @param object * @param propertyName * @return true If the property was shortened. */ public static boolean shortenProperty( final Class<?> clazz, final Object object, final String propertyName) { final Integer length = getPropertyLength(clazz, propertyName); if (length == null) { return false; } final String value = (String) BeanHelper.getProperty(object, propertyName); if (value != null && value.length() > length) { BeanHelper.setProperty(object, propertyName, value.substring(0, length - 1)); return true; } return false; }
public static void putPageParameters( final ISelectCallerPage callerPage, final Object dataObject, final Object filterObject, final PageParameters pageParameters, final String[] bookmarkableProperties) { if (bookmarkableProperties == null) { return; } // final String pre = prefix != null ? prefix + "." : ""; for (final String propertyString : bookmarkableProperties) { final InitialPageParameterHolder paramHolder = new InitialPageParameterHolder(propertyString); final Object bean; if (paramHolder.isFilterParameter() == true) { bean = filterObject; } else { bean = dataObject; } try { final Object value = BeanHelper.getProperty(bean, paramHolder.property); WicketUtils.putPageParameter(pageParameters, paramHolder.prefix + paramHolder.alias, value); } catch (final Exception ex) { log.warn( "Couldn't put page parameter '" + paramHolder.property + "' of bean '" + bean + "'. Ignoring this parameter."); } } }
/** * At least one parameter should be given for setting the fill the bean with all book-markable * properties (absent properties will be set to zero). If the given bean is an instance of {@link * ISelectCallerPage} then the select/unselect methods are used, otherwise the properties will set * directly of the given bean. * * @param bean * @param parameters * @param prefix * @param bookmarkableProperties */ public static void evaluatePageParameters( final ISelectCallerPage callerPage, final Object dataObject, final Object filter, final PageParameters parameters, final String[] bookmarkableProperties) { if (bookmarkableProperties == null) { return; } // First check if any parameter is given: boolean useParameters = false; for (final String str : bookmarkableProperties) { final InitialPageParameterHolder paramHolder = new InitialPageParameterHolder(str); if (hasParameter(parameters, paramHolder.prefix + paramHolder.property) == true || hasParameter(parameters, paramHolder.prefix + paramHolder.alias) == true) { useParameters = true; break; } } if (useParameters == false) { // No book-markable parameters found. return; } for (final String str : bookmarkableProperties) { final InitialPageParameterHolder paramHolder = new InitialPageParameterHolder(str); String key = null; if (hasParameter(parameters, paramHolder.prefix + paramHolder.property) == true) { key = paramHolder.property; } else if (hasParameter(parameters, paramHolder.prefix + paramHolder.alias) == true) { key = paramHolder.alias; } if (paramHolder.isCallerPageParameter() == true) { if (callerPage == null) { log.warn("PageParameter '" + str + "' ignored, ISelectCallerPage isn't given."); } else if (key == null) { callerPage.unselect(paramHolder.property); } else { callerPage.select( paramHolder.property, parameters.get(paramHolder.prefix + key).toString()); } } else { try { final Object bean; if (paramHolder.isFilterParameter() == true) { // Use filter object bean = filter; if (bean == null) { log.warn("PageParameter '" + str + "' ignored, filter isn't given."); continue; } } else { bean = dataObject; if (bean == null) { log.warn("PageParameter '" + str + "' ignored, dataObject isn't given."); continue; } } final Method method = BeanHelper.determineGetter(bean.getClass(), paramHolder.property); if (key == null) { BeanHelper.setProperty( bean, paramHolder.property, ClassHelper.getDefaultType(method.getReturnType())); } else { final Object value = WicketUtils.getPageParameter( parameters, paramHolder.prefix + key, method.getReturnType()); BeanHelper.setProperty(bean, paramHolder.property, value); } } catch (final Exception ex) { log.warn("Property '" + key + "' not found. Ignoring URL parameter."); } } } }