[Wicket-user] How to programatically link to a css or a script ?
Hello, I have started using Wicket few weeks ago and I am still unable to find simple solutions to simple problems ! The problem I am facing now (after many others !) is to link to a resource at run time. For example, to link to a css, I am using : link wicket:id=menucss type=text/css in the HTML template and add(new StyleSheetReference(menucss, getClass(), menu.css)); or add(new StyleSheetReference(menucss, new ResourceReference(menu.css))); Although the file menu.css is in the same directory as the page class, I only get an error message : Unable to resolve shared resource [ResourceReference name = menu.css, scope = class wicket.Application, locale = null, style = null] Thanks for any advice ! BTW, I am posting this from Nable since my mail was refused by the list server because I have no posmaster address in my domain. This is not very practical ! Pierre-Yves -- View this message in context: http://www.nabble.com/How-to-programatically-link-to-a-css-or-a-script---tf1988255.html#a5456479 Sent from the Wicket - User forum at Nabble.com. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Hey On Sun, 2006-07-23 at 08:38 -0700, Peewhy wrote: add(new StyleSheetReference(menucss, getClass(), menu.css)); is getClass() returning the correct class which is in the same package as menu.css? To be sure you could instead use MyPageWhichIsInTheSamePackage.class or something like that. add(new StyleSheetReference(menucss, new ResourceReference(menu.css))); This looks for menu.css in the same package as your MyApplication. Use the format above instead. BTW, I am posting this from Nable since my mail was refused by the list server because I have no posmaster address in my domain. This is not very practical ! http://sourceforge.net/docs/C04/en/#s_no_postmaster Regards Frank Bille - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Hello, I have started using Wicket few weeks ago and I am still unable to find simple solutions to simple problems ! The problem I am facing now (after many others !) is to link to a resource at run time. For example, to link to a css, I am using : link wicket:id=menucss type=text/css in the HTML template and add(new StyleSheetReference(menucss, getClass(), menu.css)); or add(new StyleSheetReference(menucss, new ResourceReference(menu.css))); Although the file menu.css is in the same directory as the page class, I only get an error message : Unable to resolve shared resource [ResourceReference name = menu.css, scope = class wicket.Application, locale = null, style = null] Thanks for any advice ! If you're running Wicket 1.2 (final) or before, you had to register shared resources in advance, using an initializer. If you use the current svn version - which if Martijn makes it will hopefully released later today or within the next few days -, that is fixed in the sense that you don't have to pre-register resources anymore. Btw, the easiest way of adding header references now - at least it's my preferred way - is to use HeaderContributors. I wrote a little bit about it here: http://chillenious.wordpress.com/2006/05/03/wicket-header-contributions-with-behaviors/ but the javadoc should hopefully be enough too. Btw, I wouldn't say this is a 'simple' problem. Wicket is about the only project that has such header contribution support for reusable components. Many other frameworks either have very rudimentary support, or not at all, requiring you to do your includes in the page (thus breaking the whole idea of having encapsulated components). If there are other issues you are struggling with, please post them here (after searching whether other people had a similar post first of course), or visit ##wicket on freenode. BTW, I am posting this from Nable since my mail was refused by the list server because I have no posmaster address in my domain. This is not very practical ! We are just using sourceforge's mailing list facility, which uses the most widely used mailing list management program in the world. Can't do better than that :) Eelco - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
add(new StyleSheetReference(menucss, new ResourceReference(menu.css))); This looks for menu.css in the same package as your MyApplication. Use the format above instead. Ah, yeah. That too :) Eelco - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Thank you very much ! It is not yet fully working, but I have no more exception. I used add(new StyleSheetReference(menucss, getClass(), stylesheets/menu/menu.css)); as Frank said and put the menu.css file where it belongs (the above directory structure starting whe the page class is). Among the remaining problems, is the fact that references to image files inside the css don't work, although this images are in the same directory as the css and I am using references such as background-image: url(button.jpg); I also tried background-image: url(/stylesheets/menu/button.jpg); after placing a copy of the button.jpg file in /stylesheets/menu/. (starting at the context root, which is by the way something IDEA likes !) It does not work either although the graphics is accessible in the browser through http://localhost:8080/learnwicket/stylesheets/menu/button.jpg (learnwicket being the context fro the application.) I am using Wicket 1.2. I did not know about HeaderContributors, but I am going to read your article asap. BTW, I have struggled with another problem about loading images dynamically at run time while having to pass not only the file name but the width, height and alt attributes. After days of experiments, I ended with this solution : WebMarkupContainer wmc = new WebMarkupContainer(image0); wmc.add(new AttributeModifier(src, new Model(images/vd-contrebasse.png))); wmc.add(new AttributeModifier(width, new Model(132))); wmc.add(new AttributeModifier(height, new Model(101))); wmc.add(new AttributeModifier(alt, new Model(Mains sur une contrebasse))); add(wmc); Although it works, it looks a bit like brute force ! (This approach also work for linking to a css file, and I suppose it could work for setting any attribute of any element, but it looks ugly ! Is there a better way to achieve this ? Thanks al lot for your help, Pierre-Yves -- View this message in context: http://www.nabble.com/How-to-programatically-link-to-a-css-or-a-script---tf1988255.html#a5457215 Sent from the Wicket - User forum at Nabble.com. - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Among the remaining problems, is the fact that references to image files inside the css don't work Probably all the same problem of not having them pre-registered. Please could you try using the version in svn (WICKET_1_2 branch), or download the intermediate version at http://sourceforge.net/project/showfiles.php?group_id=119783package_id=173489release_id=428730 ? There are many components, like the Tree, DatePicker, YUI Slider and Calendar etc that work with relative images like that. So far - besides that pre-registering - that didn't give any problems. BTW, I have struggled with another problem about loading images dynamically at run time while having to pass not only the file name but the width, height and alt attributes. After days of experiments, I ended with this solution : WebMarkupContainer wmc = new WebMarkupContainer(image0); wmc.add(new AttributeModifier(src, new Model(images/vd-contrebasse.png))); wmc.add(new AttributeModifier(width, new Model(132))); wmc.add(new AttributeModifier(height, new Model(101))); wmc.add(new AttributeModifier(alt, new Model(Mains sur une contrebasse))); add(wmc); Although it works, it looks a bit like brute force ! (This approach also work for linking to a css file, and I suppose it could work for setting any attribute of any element, but it looks ugly ! Is there a better way to achieve this ? Well, first off, programming will always take a few lines here and there. The whole trick with Wicket and it's philosophy of reusable components is that you hide the ugly parts in components and expose a nice API on them. Instead of those static models (new Model(value)), use dynamic models that e.g. work on properties of your component (new PropertyModel(this, alt)). Furthermore, instead of using attribute modifiers, you could e.g. override onComponentTag body, and do your attribute modification there like: openTag.getAttributes().put(key, value) or in 2.0 (alpha currently) you can even do it int the constructor: getMarkupAttributes().put(key, value); Eelco - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
class MyImage extends WebComponent { private int width; private int height; private string url; private string text; public myimage(string id, string url, string text, int width, int height) { super(id); this.url=""> ... } void oncomponenttag(tag tag) { checkcomponenttag(tag, img); tag.put(src,url); tag.put(alt, text); tag.put(width, width); tag.put(height, height); }}add(new MyImage(img1, foo.gif, bar, 200, 330); add(new MyImage(img2, foo2.gif, bar2, 232, 523);-IgorOn 7/23/06, Eelco Hillenius [EMAIL PROTECTED] wrote: Among the remaining problems, is the fact that references to image files inside the css don't workProbably all the same problem of not having them pre-registered.Please could you try using the version in svn (WICKET_1_2 branch), ordownload the intermediate version at http://sourceforge.net/project/showfiles.php?group_id=119783package_id=173489release_id=428730 ?There are many components, like the Tree, DatePicker, YUI Slider andCalendar etc that work with relative images like that. So far -besides that pre-registering - that didn't give any problems. BTW, I have struggled with another problem about loading images dynamically at run time while having to pass not only the file name but the width, height and alt attributes. After days of experiments, I ended with this solution : WebMarkupContainer wmc = new WebMarkupContainer(image0); wmc.add(new AttributeModifier(src, new Model(images/vd-contrebasse.png))); wmc.add(new AttributeModifier(width, new Model(132))); wmc.add(new AttributeModifier(height, new Model(101))); wmc.add(new AttributeModifier(alt, new Model(Mains sur une contrebasse))); add(wmc); Although it works, it looks a bit like brute force ! (This approach also work for linking to a css file, and I suppose it could work for setting any attribute of any element, but it looks ugly ! Is there a better way to achieve this ?Well, first off, programming will always take a few lines here andthere. The whole trick with Wicket and it's philosophy of reusable components is that you hide the ugly parts in components and expose anice API on them.Instead of those static models (new Model(value)), use dynamicmodels that e.g. work on properties of your component (new PropertyModel(this, alt)).Furthermore, instead of using attribute modifiers, you could e.g.override onComponentTag body, and do your attribute modification therelike: openTag.getAttributes().put(key, value) or in 2.0 (alphacurrently) you can even do it int the constructor:getMarkupAttributes().put(key, value);Eelco-Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share youropinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___Wicket-user mailing listWicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Action speaks louder than words... Eelco :) On 7/23/06, Igor Vaynberg [EMAIL PROTECTED] wrote: class MyImage extends WebComponent { private int width; private int height; private string url; private string text; public myimage(string id, string url, string text, int width, int height) { super(id); this.url=url; ... } void oncomponenttag(tag tag) { checkcomponenttag(tag, img); tag.put(src,url); tag.put(alt, text); tag.put(width, width); tag.put(height, height); } } add(new MyImage(img1, foo.gif, bar, 200, 330); add(new MyImage(img2, foo2.gif, bar2, 232, 523); -Igor On 7/23/06, Eelco Hillenius [EMAIL PROTECTED] wrote: Among the remaining problems, is the fact that references to image files inside the css don't work Probably all the same problem of not having them pre-registered. Please could you try using the version in svn (WICKET_1_2 branch), or download the intermediate version at http://sourceforge.net/project/showfiles.php?group_id=119783package_id=173489release_id=428730 ? There are many components, like the Tree, DatePicker, YUI Slider and Calendar etc that work with relative images like that. So far - besides that pre-registering - that didn't give any problems. BTW, I have struggled with another problem about loading images dynamically at run time while having to pass not only the file name but the width, height and alt attributes. After days of experiments, I ended with this solution : WebMarkupContainer wmc = new WebMarkupContainer(image0); wmc.add(new AttributeModifier(src, new Model(images/vd-contrebasse.png))); wmc.add(new AttributeModifier(width, new Model(132))); wmc.add(new AttributeModifier(height, new Model(101))); wmc.add(new AttributeModifier(alt, new Model(Mains sur une contrebasse))); add(wmc); Although it works, it looks a bit like brute force ! (This approach also work for linking to a css file, and I suppose it could work for setting any attribute of any element, but it looks ugly ! Is there a better way to achieve this ? Well, first off, programming will always take a few lines here and there. The whole trick with Wicket and it's philosophy of reusable components is that you hide the ugly parts in components and expose a nice API on them. Instead of those static models (new Model(value)), use dynamic models that e.g. work on properties of your component (new PropertyModel(this, alt)). Furthermore, instead of using attribute modifiers, you could e.g. override onComponentTag body, and do your attribute modification there like: openTag.getAttributes().put(key, value) or in 2.0 (alpha currently) you can even do it int the constructor: getMarkupAttributes().put(key, value); Eelco - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
Re: [Wicket-user] How to programatically link to a css or a script ?
Thanks Igor ! It looks really smart and works perfectly. I have now to read Eelco's explanations to understand how all this is working, and try 1.2.1. Igor Vaynberg a écrit : class MyImage extends WebComponent { private int width; private int height; private string url; private string text; public myimage(string id, string url, string text, int width, int height) { super(id); this.url=url; ... } void oncomponenttag(tag tag) { checkcomponenttag(tag, img); tag.put(src,url); tag.put(alt, text); tag.put(width, width); tag.put(height, height); } } add(new MyImage(img1, foo.gif, bar, 200, 330); add(new MyImage(img2, foo2.gif, bar2, 232, 523); -Igor On 7/23/06, *Eelco Hillenius* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Among the remaining problems, is the fact that references to image files inside the css don't work Probably all the same problem of not having them pre-registered. Please could you try using the version in svn (WICKET_1_2 branch), or download the intermediate version at http://sourceforge.net/project/showfiles.php?group_id=119783package_id=173489release_id=428730 http://sourceforge.net/project/showfiles.php?group_id=119783package_id=173489release_id=428730 ? There are many components, like the Tree, DatePicker, YUI Slider and Calendar etc that work with relative images like that. So far - besides that pre-registering - that didn't give any problems. BTW, I have struggled with another problem about loading images dynamically at run time while having to pass not only the file name but the width, height and alt attributes. After days of experiments, I ended with this solution : WebMarkupContainer wmc = new WebMarkupContainer(image0); wmc.add(new AttributeModifier(src, new Model(images/vd-contrebasse.png))); wmc.add(new AttributeModifier(width, new Model(132))); wmc.add(new AttributeModifier(height, new Model(101))); wmc.add(new AttributeModifier(alt, new Model(Mains sur une contrebasse))); add(wmc); Although it works, it looks a bit like brute force ! (This approach also work for linking to a css file, and I suppose it could work for setting any attribute of any element, but it looks ugly ! Is there a better way to achieve this ? Well, first off, programming will always take a few lines here and there. The whole trick with Wicket and it's philosophy of reusable components is that you hide the ugly parts in components and expose a nice API on them. Instead of those static models (new Model(value)), use dynamic models that e.g. work on properties of your component (new PropertyModel(this, alt)). Furthermore, instead of using attribute modifiers, you could e.g. override onComponentTag body, and do your attribute modification there like: openTag.getAttributes().put(key, value) or in 2.0 (alpha currently) you can even do it int the constructor: getMarkupAttributes().put(key, value); Eelco - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net mailto:Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV ___ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user - Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT business topics through brief surveys -- and earn cash