コード例 #1
0
 /**
  * If value is null or value is default value then nothing is done. Otherwise the given value is
  * added as page parameter under the given key. Dates and TimePeriods are converted and can be
  * gotten by {@link #getPageParameter(PageParameters, String, Class)}.
  *
  * @param pageParameters
  * @param key
  * @param value
  * @see ClassHelper#isDefaultType(Class, Object)
  */
 public static void putPageParameter(
     final PageParameters pageParameters, final String key, final Object value) {
   if (value == null) {
     // Do not put null values to page parameters.
   } else if (ClassHelper.isDefaultType(value.getClass(), value)) {
     // Do not put default values to page parameters.
   } else if (value instanceof Date) {
     addOrReplaceParameter(pageParameters, key, ((Date) value).getTime());
   } else if (value instanceof TimePeriod) {
     addOrReplaceParameter(
         pageParameters,
         key,
         ((TimePeriod) value).getFromDate().getTime()
             + "-"
             + ((TimePeriod) value).getToDate().getTime());
   } else {
     addOrReplaceParameter(pageParameters, key, value);
   }
 }
コード例 #2
0
 /**
  * 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.");
       }
     }
   }
 }