By the way, there are three immediate things I'd like contribute/work on:

1) Adding my so-called WicketUtils methods to ValueMap (see below)

2) Fixing a bug in MixedParamUrlCodingStrategy where anything other than a
String in the map causes a class cast exception.  It would be an easy fix a
'ValueMap' or 'PageParameters' was passed down into appendParameters.  I
fixed it by copying the getString() method from ValueMap to a local copy of
MixedParamUrlCodingStrategy.

3) Use Annotations to handle mounting.  Instead of putting all mount logic
in the Application class, you could annotate your pages with something like
@Mount( strategy=foo.class, params=x,y,z ).  Then upon initialization,
Wicket could scan the class path and auto-mount these annotated pages. 
Scanning the classpath is pretty easy using some spring-core functionality. 
I don't know if the Spring license is compatible with Apache, so this might
need to be a contrib feature.

-Doug


Doug Donohoe wrote:
> 
> public class WicketUtils
> {
>     //private static Logger logger = Logger.getLogger(WicketUtils.class);
> 
>     /**
>      * Return an int param, returning 'def' if none is defined or
>      * the value is not a valid integer
>      */
>     public static int getInteger(PageParameters params, String name, int
> def)
>     {
>         try
>         {
>             return params.getInt(name, def);
>         }
>         catch (StringValueConversionException ignored)
>         {
>             return def;
>         }
>     }
> 
>     /**
>      * Return an Long param, returning 'def' if none is defined or
>      * the value is not a valid long
>      */
>     public static long getLong(PageParameters params, String name, int
> def)
>     {
>         try
>         {
>             return params.getLong(name, def);
>         }
>         catch (StringValueConversionException ignored)
>         {
>             return def;
>         }
>     }
> 
>     /**
>      * return an Integer param, return null if not defined or the value
>      * is not a valid Integer
>      */
>     public static Integer getInteger(PageParameters params, String name)
>     {
>         if (!params.containsKey(name)) return null;
>         
>         try
>         {
>             return params.getInt(name);
>         }
>         catch (StringValueConversionException ignored)
>         {
>             return null;
>         }
>     }
> 
>     /**
>      * return a Long param, return null if not defined or the value
>      * is not a valid Long
>      */
>     public static Long getLong(PageParameters params, String name)
>     {
>         if (!params.containsKey(name)) return null;
> 
>         try
>         {
>             return params.getLong(name);
>         }
>         catch (StringValueConversionException ignored)
>         {
>             return null;
>         }
>     }
> 
>     /**
>      * Get enum, returning default value if not found.  Note:  deafult
> value cannot be null
>      * since it is used to determine the Enum class.
>      */
>     public static <T extends Enum<T>> T getEnum(PageParameters params,
> String name, T def)
>     {
>         if (def == null) throw new IllegalArgumentException("Default value
> cannot be null");
>         return getEnumImpl(params, name, def.getClass(), def);
>     }
> 
>     /**
>      * Get enum, returning null if not found.
>      */
>     public static <T extends Enum<T>> T getEnum(PageParameters params,
> String name, Class<T> eClass)
>     {
>         return getEnumImpl(params, name, eClass, null);
>     }
> 
>     /**
>      * Get enum, returning default value if not found.
>      */
>     public static <T extends Enum<T>> T getEnum(PageParameters params,
> String name, Class<T> eClass, T def)
>     {
>         return getEnumImpl(params, name, eClass, def);
>     }
> 
>     /**
>      * get enum implementation.
>      */
>     @SuppressWarnings({"unchecked"})
>     private static <T extends Enum<T>> T getEnumImpl(PageParameters
> params, String name, Class<?> eClass, T def)
>     {
>         if (eClass == null) throw new IllegalArgumentException("eClass
> value cannot be null");
> 
>         String value = params.getString(name);
>         if (value == null) return def;
> 
>         Method valueOf = null;
>         try
>         {
>             valueOf = eClass.getMethod("valueOf", String.class);
>         }
>         catch (NoSuchMethodException e)
>         {
>             throw new RuntimeException("Could not find method
> valueOf(String s) for " + eClass.getName(), e);
>         }
> 
>         try
>         {
>             return (T) valueOf.invoke(eClass, value);
>         }
>         catch (IllegalAccessException e)
>         {
>             throw new RuntimeException("Could not invoke method
> valueOf(String s) on " + eClass.getName(), e);
>         }
>         catch (InvocationTargetException e)
>         {
>             // IllegalArgumentException thrown if enum isn't defined -
> just return default
>             if (e.getCause() instanceof IllegalArgumentException)
>             {
>                 return def;
>             }
>             throw new RuntimeException(e); // shouldn't happen
>         }
>     }
> 
> }
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-contribute---wicket-1.4-plans-tp17034501p17035130.html
Sent from the Wicket - Dev mailing list archive at Nabble.com.

Reply via email to