i just realized that might not be a transparent statement...
for example, notice that if you run the pub example (tomorrow... ;-)) the url for the US beer image is this (in the US):
http://localhost:8080/pub/resources/wicket.examples.pub.Home_Beer.gif
the resource is automatically "scoped" by the class associated with the markup that contained it (the page wicket.examples.pub.Home, in this case)
in other words, it's shared across sessions (since every ResourceReference in every session will point to the same Resource), but it is NOT shared "application-wide" because the shared image resource is scoped.
you /can/ share images application-wide. for example, you could create a cancelButton image that has Application.class for its scope. this image could then be used everywhere in your app via the Application.class scope.
but to create a single cancelButton image that is shared across your entire application (every session and every component on every page), you can simply use image resource factories.
this is demonstrated quite nicely in the FormInput example. FormInput adds an ImageButton like this:
add(new ImageButton("saveButton"));and then in the markup, it simply does this:
<input wicket:id="saveButton" type="image" value="buttonFactory:save:Save"/>
internally, wicket uses the Application.class scope for factory images of this type so they will be pooled across the whole application. the resource factory "buttonFactory" is installed by default in Application as a DefaultButtonImageResourceFactory (although you can change the look of every button in your application at once by replacing this!) and the factory creates the button image with the specification after the second colon ("Save"). the format of this specification is dependent on the resource factory. now, to wrap up this long story, the middle value "save" in the resource specification string is the name under which the factory resource should be shared (you can omit if you don't want sharing and just say "buttonFactory::Save"). so this little syntax is the equivalent of something like:
add(new ImageButton("saveButton", new ResourceReference(Application.class, "save")
{
public void newResource()
{
getApplication().getResourceFactory("buttonFactory").newResource("Save", getLocale(), getStyle());
}
});
(i didn't compile this, so it may not be 100% accurate... but it's close)
image resource factories are a great way to create really efficient images on the fly.
jon
Jonathan Locke wrote:
yes. if you reference a static image using the src="..." magic in Image, it will be shared using the scope for the markup in which the image appears.
Gili wrote:
Ok... Johan's original sentence: "And we should teach people to never return just images from files under the same, not shared/static resource url." does not read as English in my head (sorry!) so I *still* do not understand what the heck you guys are talking about.
Jon, are you saying that Wicket will now automatically take all images added into a component and share them application-wide? I assume this is only for static images?
Gili
Jonathan Locke wrote:
actually, it /was/ bad practice. it is now automatically efficient. if you look at the /very same/ pub example now, you'll see that
add(new Image("beer"));
and
<img wicket:id = "beer" src = "Beer.gif"/>
results in this URL
http://localhost:8080/pub/resources/wicket.examples.pub.Home_Beer.gif
in other words (gili, are you listening?), you don't have to do anything to make your packaged resources cached and efficient now. just attach an Image component to the IMG tag and it will automatically do efficient resource sharing and referencing.
of course, if you want more control, you have it. but this takes care of a very common case (want localized, packaged image resources).
i think this is the beauty of good encapsulation in OO programming. if we exposed URLs all over the place, for example, we couldn't do this kind of thing. since we actually have abstractions for images, resources and resource references... i can go make globally optimizing changes like this without affecting anyone.
Gili wrote:
I don't get it. What is bad practice? Can you rephrase it?
Gili
Johan Compagner wrote:
I will make it so that when caching is not allowed i don't set anything (so also not the last modified time of the file)
But that example is ofcourse wrong.. And we should teach people to never return just images from files under
the same, not shared/static resource url. This is just bad practice.
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Wicket-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-develop
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Wicket-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-develop
------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Wicket-develop mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/wicket-develop
