nice job finishing this up, johan!
Johan Compagner wrote:
Hi,
After a late night refactoring with jonathan and finishing/testing it
today, i think we finally nailed all resouce problems
The datapicker works perfectly now as far as i can test and it is much
less error prone.
To give you all an example:
DataPicker is a wicket extensions component and we have now a:
META-INF/wicket-component-initializers.txt
<cid:[email protected]> file
in that file we have this content:
wicket.extensions.markup.html.datepicker.DatePickerComponentInitializer
so we point to a class here, that class implements
IComponentInitializer and looks like this:
public class DatePickerComponentInitializer implements
IComponentInitializer
{
private static String LANGUAGE_AF = "lang/calendar-af.js";
private static String LANGUAGE_AL = "lang/calendar-al.js";
<SKIP lot of languages>
/** locale to language map. */
private static final Map localeToLanguageReference = new HashMap();
static
{
// fill our default map. Note that new Locale("en", "",
"").getLanguage() is to avoid
// future breaks because of the instable standard (read about
this in Locale.getLanguage()
localeToLanguageReference.put(new Locale("af", "",
"").getLanguage(), LANGUAGE_AF);
localeToLanguageReference.put(new Locale("al", "",
"").getLanguage(), LANGUAGE_AL);
<SKIP lot of languages>
}
/**
* @see wicket.IComponentInitializer#init(wicket.Application)
*/
public void init(Application application)
{
// register dependencies
PackageResource.bind(application, DatePickerSettings.class,
"style/aqua/active-bg.gif");
PackageResource.bind(application, DatePickerSettings.class,
"style/aqua/dark-bg.gif");
<SKIP lot of resources binding>
PackageResource.bind(application, DatePicker.class,
"calendar.js");
PackageResource.bind(application, DatePicker.class,
"calendar-setup.js");
Iterator it = localeToLanguageReference.values().iterator();
while(it.hasNext())
{
String path = (String)it.next();
PackageResource.bind(application, DatePickerSettings.class,
path);
}
}
The init method of this class is called when an wicket application is
started/initialized.
So that every static resource the datapicker could have is initialized
right and added to the
shared resource pool.
We have to do this because of server restarts or clustering. So that
we know that all the resources are there
on the any server that gets hit by a url to an PackageResource.
The nice extra thing we gain now. We can now use
PackageResourceReferences statically
(still not the preferred way, but i do get that a lot of people are
doing that)
Because every resource you already binded in you're
IComponentInitializer.init method
doesn't have to be binded anymore so we have now 3 constructors of
PackageResource
2 with an application object that will directly bind.
And one without an application object that doesn't bind anymore.
PLEASE NOTE this! If you are refactoring youre code any call to the
StaticResource(Class,String) should point now
to PackageResource(Application,Class,String) or point it to
PackageResource(Class,String)
but then you have to make sure that is is already binded through an
IComponentInitializer
or that getPath() is called (that will try to bind anyway)
If you have now things like this to just add resources to the
sharedresources:
new StaticResourceReference(class,css1);
new StaticResourceReference(class,css2);
new StaticResourceReference(class,js1);
new StaticResourceReference(class,image1);
those should be replaced by PackageResource.bind() and if you want to
make sure it always works
do it in a IComponentInitializer
johan
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle
Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing
& QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user