Re: Re: Re: @Asset problem
Thank you all... Will try them all out. Srini. On 11/28/06, Sam Gendler <[EMAIL PROTECTED]> wrote: Incidentally, in our case, we have a mechanism within spring that will detect the existence of a context file in a location outside the war file and use that to override bean definitions in the context file(s) inside the war file. I don't konw that such a mechanism is possible within hivemind (but it probably is), and even without it, it is much easier to modify an xml file in a war file when you deploy than it is to recompile a java class and push that into the war. --sam
Re: Re: Re: @Asset problem
Incidentally, in our case, we have a mechanism within spring that will detect the existence of a context file in a location outside the war file and use that to override bean definitions in the context file(s) inside the war file. I don't konw that such a mechanism is possible within hivemind (but it probably is), and even without it, it is much easier to modify an xml file in a war file when you deploy than it is to recompile a java class and push that into the war. --sam On 11/28/06, Sam Gendler <[EMAIL PROTECTED]> wrote: OK, here's a bit of a convoluted solution, but it works. In my case, I'm using spring, but you could do the exact same thing within hivemind. I've got an object that has some string properties that I want to configure at run time. Let's call is CssOverrides. It can be populated with a list of strings from the config file (either applicationContext.xml or hivemodule.xml). Inject that object into your Header component: @InjectObject("spring:cssOverrides") public abstract CssOverrides getCssOverrides(); Then I've got the following code in my Header component. public void finishLoad(IRequestCycle cycle, IPageLoader loader, IComponentSpecification specification) { super.finishLoad(cycle, loader, specification); CssOverrides overrides = getCssOverrides(); if (overrides!=null && overrides.getCssFileList()!=null) { int i = 0; additionalStylesheets = new ArrayList(overrides.getCssFileList().size()); for (String cssFile : overrides.getCssFileList()) { if (cssFile==null || cssFile.length()==0) { continue; } IAsset styleAsset; if (PageUtils.isAbsoluteUrl(cssFile)) { styleAsset = new ExternalAsset(cssFile, getLocation()); } else { if (!cssFile.startsWith("/")) { cssFile = "/" + cssFile; //pathinfo must start with '/' } styleAsset = new ContextAsset( getWebRequest().getContextPath(), new ContextResource(getServletContext(), cssFile), getLocation(), cycle); } additionalStylesheets.add(styleAsset); } } } You've now got a list of IAssets in the additionalStylesheets list, and you can use them just as you would a normal asset. In our case, we've got defaults that specifically uglify the interface and then override them with the correct values in the production environment. This makes it readily apparent when you are working on a production box and when you are on a dev or qa box. --sam On 11/27/06, andyhot <[EMAIL PROTECTED]> wrote: > Srinivas Yermal wrote: > > Thanks guys! > > I think I will just go with the "putting it in html" solution. The only > > problem with this is that it creates two head elements, since I use > > @Shell. > > http://wiki.apache.org/tapestry/CustomTagsInShell > > > > > BTW, I couldnt find import component or annotation. Can you please > > point me > > to any documentation that you have. > > > > Thanks, > > Srini. > > > > On 11/27/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >> > >> We do something similar; you can have your @Border *always* pull in a > >> single stylesheet that has a single line: > >> > >> @import ("http://your.style.server/blah.css";) > >> > >> You host blah.css off Apache (or Tomcat, or whatever) outside of the > >> context of your webapp and change at will. You can use nested @imports > >> (e.g., blah.css is maybe just a collection of @imports as well). > >> > >> HTH, > >> Tom > >> > > > > > -- > Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr > Tapestry / Tacos developer > Open Source / J2EE Consulting > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re: @Asset problem
OK, here's a bit of a convoluted solution, but it works. In my case, I'm using spring, but you could do the exact same thing within hivemind. I've got an object that has some string properties that I want to configure at run time. Let's call is CssOverrides. It can be populated with a list of strings from the config file (either applicationContext.xml or hivemodule.xml). Inject that object into your Header component: @InjectObject("spring:cssOverrides") public abstract CssOverrides getCssOverrides(); Then I've got the following code in my Header component. public void finishLoad(IRequestCycle cycle, IPageLoader loader, IComponentSpecification specification) { super.finishLoad(cycle, loader, specification); CssOverrides overrides = getCssOverrides(); if (overrides!=null && overrides.getCssFileList()!=null) { int i = 0; additionalStylesheets = new ArrayList(overrides.getCssFileList().size()); for (String cssFile : overrides.getCssFileList()) { if (cssFile==null || cssFile.length()==0) { continue; } IAsset styleAsset; if (PageUtils.isAbsoluteUrl(cssFile)) { styleAsset = new ExternalAsset(cssFile, getLocation()); } else { if (!cssFile.startsWith("/")) { cssFile = "/" + cssFile; //pathinfo must start with '/' } styleAsset = new ContextAsset( getWebRequest().getContextPath(), new ContextResource(getServletContext(), cssFile), getLocation(), cycle); } additionalStylesheets.add(styleAsset); } } } You've now got a list of IAssets in the additionalStylesheets list, and you can use them just as you would a normal asset. In our case, we've got defaults that specifically uglify the interface and then override them with the correct values in the production environment. This makes it readily apparent when you are working on a production box and when you are on a dev or qa box. --sam On 11/27/06, andyhot <[EMAIL PROTECTED]> wrote: Srinivas Yermal wrote: > Thanks guys! > I think I will just go with the "putting it in html" solution. The only > problem with this is that it creates two head elements, since I use > @Shell. http://wiki.apache.org/tapestry/CustomTagsInShell > > BTW, I couldnt find import component or annotation. Can you please > point me > to any documentation that you have. > > Thanks, > Srini. > > On 11/27/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> >> We do something similar; you can have your @Border *always* pull in a >> single stylesheet that has a single line: >> >> @import ("http://your.style.server/blah.css";) >> >> You host blah.css off Apache (or Tomcat, or whatever) outside of the >> context of your webapp and change at will. You can use nested @imports >> (e.g., blah.css is maybe just a collection of @imports as well). >> >> HTH, >> Tom >> > -- Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr Tapestry / Tacos developer Open Source / J2EE Consulting - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: @Asset problem
Srinivas Yermal wrote: > Thanks guys! > I think I will just go with the "putting it in html" solution. The only > problem with this is that it creates two head elements, since I use > @Shell. http://wiki.apache.org/tapestry/CustomTagsInShell > > BTW, I couldnt find import component or annotation. Can you please > point me > to any documentation that you have. > > Thanks, > Srini. > > On 11/27/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> >> We do something similar; you can have your @Border *always* pull in a >> single stylesheet that has a single line: >> >> @import ("http://your.style.server/blah.css";) >> >> You host blah.css off Apache (or Tomcat, or whatever) outside of the >> context of your webapp and change at will. You can use nested @imports >> (e.g., blah.css is maybe just a collection of @imports as well). >> >> HTH, >> Tom >> > -- Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr Tapestry / Tacos developer Open Source / J2EE Consulting - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: @Asset problem
Thanks guys! I think I will just go with the "putting it in html" solution. The only problem with this is that it creates two head elements, since I use @Shell. BTW, I couldnt find import component or annotation. Can you please point me to any documentation that you have. Thanks, Srini. On 11/27/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: We do something similar; you can have your @Border *always* pull in a single stylesheet that has a single line: @import ("http://your.style.server/blah.css";) You host blah.css off Apache (or Tomcat, or whatever) outside of the context of your webapp and change at will. You can use nested @imports (e.g., blah.css is maybe just a collection of @imports as well). HTH, Tom
RE: @Asset problem
We do something similar; you can have your @Border *always* pull in a single stylesheet that has a single line: @import ("http://your.style.server/blah.css";) You host blah.css off Apache (or Tomcat, or whatever) outside of the context of your webapp and change at will. You can use nested @imports (e.g., blah.css is maybe just a collection of @imports as well). HTH, Tom -Original Message- From: Srinivas Yermal [mailto:[EMAIL PROTECTED] Sent: Monday, November 27, 2006 8:57 AM To: Tapestry users Subject: @Asset problem Hi, I am now a big fan of tapestry annotations since everything stays neatly in one place, except in one area which still bothers me. I want to specify assets like stylesheets and such in a Border component that can be used by the rest of the pages and the whole app looks uniform and so on and so forth. But I also want to be able to change the stylesheet name at deploy time, without having to recompile and redistribute the war file, in other words bother the developers whenever I want to change it. So I thought may be I can declare it as a key (stylesheet = css/mycss.css) in the app.propertiesfile and pick it up in Border component. @Asset("message:stylesheet") - This isnt working. I dont know whether its supposed to. I went ahead and tried this - public IAsset getStylesheet() { return getAsset(getMessages().getMessage("stylesheet")); } However this code always returns null. I guess the asset needs to be registered much ahead, (there is some code I see in AbstractComponent which uses a map to store references of assets). So how am I supposed to setup dynamic assets? Is there a way of creating assets when required? I remember having read something about this but I am unable to find it. I would be grateful if you could point me in the right direction. Thanks, Srini. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: @Asset problem
You are mixing between creating assets and defining them. The annotation is defining an asset, and what you probably want is create a new one on the fly.- To do so, you need to inject one of the AssetFactory services from here, and use it to create one on the fly... http://tapestry.apache.org/tapestry4/tapestry/hivedocs/module/tapestry.asset.html Cheers, Ron Srinivas Yermal wrote: Hi, I am now a big fan of tapestry annotations since everything stays neatly in one place, except in one area which still bothers me. I want to specify assets like stylesheets and such in a Border component that can be used by the rest of the pages and the whole app looks uniform and so on and so forth. But I also want to be able to change the stylesheet name at deploy time, without having to recompile and redistribute the war file, in other words bother the developers whenever I want to change it. So I thought may be I can declare it as a key (stylesheet = css/mycss.css) in the app.propertiesfile and pick it up in Border component. @Asset("message:stylesheet") - This isnt working. I dont know whether its supposed to. I went ahead and tried this - public IAsset getStylesheet() { return getAsset(getMessages().getMessage("stylesheet")); } However this code always returns null. I guess the asset needs to be registered much ahead, (there is some code I see in AbstractComponent which uses a map to store references of assets). So how am I supposed to setup dynamic assets? Is there a way of creating assets when required? I remember having read something about this but I am unable to find it. I would be grateful if you could point me in the right direction. Thanks, Srini. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: @Asset problem
You could implement http://tapestry.apache.org/tapestry4/tapestry/apidocs/org/apache/tapestry/IAsset.html esp. the buildURL method and make it work the way you like You could also spare creating assets for css, and include them in your Border the html way... If you're on 4.1.x versions, this component is helpful http://tapestry.apache.org/tapestry4.1/components/general/style.html Srinivas Yermal wrote: > Hi, > > I am now a big fan of tapestry annotations since everything stays > neatly in > one place, except in one area which still bothers me. I want to specify > assets like stylesheets and such in a Border component that can be > used by > the rest of the pages and the whole app looks uniform and so on and so > forth. > > But I also want to be able to change the stylesheet name at deploy time, > without having to recompile and redistribute the war file, in other words > bother the developers whenever I want to change it. So I thought may be I > can declare it as a key (stylesheet = css/mycss.css) in the > app.propertiesfile and pick it up in Border component. > > @Asset("message:stylesheet") - This isnt working. I dont know whether its > supposed to. No, it's not supposed to work this way > > I went ahead and tried this - > public IAsset getStylesheet() { >return getAsset(getMessages().getMessage("stylesheet")); > } > > However this code always returns null. I guess the asset needs to be > registered much ahead, (there is some code I see in AbstractComponent > which > uses a map to store references of assets). You're right here... > So how am I supposed to setup > dynamic assets? Is there a way of creating assets when required? I > remember > having read something about this but I am unable to find it. I would be > grateful if you could point me in the right direction. > > Thanks, > Srini. > -- Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr Tapestry / Tacos developer Open Source / J2EE Consulting - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]