Kent Tong wrote:
Sebastiaan van Erk wrote:As far as I can tell, there's still only 1 resource, which has the locale of the page (at creation time).Every time the page is rendered, it will generate a different variant of the resource reference due to the setLocale() call. Sebastiaan van Erk wrote:But I have a link on the page which allows you to change the locale. This link is stateful, so it just calls the callback on the current page and sets the locale.No problem. If the link is a normal link (not ajax), you'll render the page again and thus will have a new resource reference. If it's ajax, you need to put the setLocale() call into a callback and refresh the link.
Your code was:
public class P1 extends WebPage {
public P1() {
ResourceReference resourceRef = new ResourceReference("cvs.pdf") {
protected Resource newResource() {
return new PDFResource(getLocale());
}
};
resourceRef.setLocale(getLocale()); //THIS IS THE LINE
ResourceLink link = new ResourceLink("link", resourceRef);
add(link);
}
}
As far as I can see, the line marked "//THIS IS THE LINE" is only called
in the constructor, which means it's called every time the page is
*constructed* and not every time the page is *rendered*.
You're right that I could do the setLocale() on the reference manually in the callback (I'd have to do that for a non-ajax locale link as well). However, I don't really like that solution either, because my switch locale links are on a ChangeLocalePanel which knows nothing about my page or the resource links on that page (and shouldn't as far as I'm concerned).
The last problem, and the problem which might actually require me to have 2 different resources is that I want the shared resources for different locales to be mounted on *different* locations, "/dowloads/resourceX_localeY.pdf". I've tried variations on the code above, but I couldn't get it working (for one, the ResourceReference class seems to require that it's string argument is the name of the shared resource, and thus I can't have 2 different mount paths which always work regardless of the locale you're in: i.e., if you're in the Dutch locale and you request /downloads/cvs_en.pdf I want you to get the English version).
Regards, Sebastiaan
----- -- Kent Tong Wicket tutorials freely available at http://www.agileskills2.org/EWDW Axis2 tutorials freely available at http://www.agileskills2.org/DWSAA
smime.p7s
Description: S/MIME Cryptographic Signature
