Hi, I recommend you to read again the article. See below some improvements:
On Wed, Feb 8, 2012 at 7:33 PM, Kayode Odeyemi <drey...@gmail.com> wrote: > On Wed, Feb 8, 2012 at 3:58 PM, Martin Grigorov <mgrigo...@apache.org>wrote: > >> Hi, >> >> Everything is possible. >> See http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/ >> You the request parameter to map to your real resource and load it. >> >> Thanks. > > I have all the classes in place now. Could you help with some pointers as > to how to use this in a Page component renderHead? I'm working with > something like this: > > private static final UrlResourceReference DASHBOARD_JS = new > UrlResourceReference( > "/WEB-INF/js/dashboard.js"); Remove that completely ^^ > > @Override > public void renderHead(IHeaderResponse response) { > response.renderJavaScriptReference(DASHBOARD_JS); Here use the url generation approach with #urlFor(new UrlResourceReference(), new PageParameters().add("dashboard.js")); This adds indexed parameter. > } > > Application.java > ---------------------- > super.mountResource("/WEB-INF/js/dashboard.js", new UrlResourceReference()); mountResource("/Dashboard/js", new UrlResourceReference()); > > ContextRelativeURLResource.java > ------------------------------------------------- > @Override > protected ResourceResponse newResourceResponse(Attributes attributes) { attributes.getPageParameters.get(0) will return you "dashboard.js". Load it with ServletContext.getResource() and with the WriteCallback write its bytes into attributes.getResponse(). > final ResourceResponse resourceResponse = new ResourceResponse(); > > if (resourceResponse.dataNeedsToBeWritten(attributes)) { > > final UrlContextResourceStream urlContextResourceStream = new > UrlContextResourceStream(path); > > resourceResponse.setContentType(urlContextResourceStream.getContentType()); > > resourceResponse.setLastModified(urlContextResourceStream.lastModifiedTime()); > resourceResponse.setFileName(path); > resourceResponse.setWriteCallback(new WriteCallback() { > > @Override > public void writeData(Attributes attributes) { > URL url = null; > try { > url = urlContextResourceStream.getResourceURL(); // > getURL uses path passed into UrlResourceStream > } catch (MalformedURLException ex) { > > throw new WicketRuntimeException(ex); > } > } > }); > } > return resourceResponse; > } > > UrlResourceReference.java > --------------------------------------- > @Override > public IResource getResource() { > return new ContextRelativeURLResource(getName()); > > } > > I'm still getting this in the logs: > /w/wicket/resource/org.apache.wicket.Application/WEB-INF/js/dashboard-ver-1328653530609.js > > Thank you. > > On Wed, Feb 8, 2012 at 5:30 PM, Kayode Odeyemi <drey...@gmail.com> wrote: >> > On Mon, Feb 6, 2012 at 3:08 PM, Martin Grigorov <mgrigo...@apache.org >> >wrote: >> > >> >> Hi, >> >> >> >> I'd not invest in AbstractResourceDependentResourceReference. >> >> This has been re-implemented in Wicket 6.0 and this class is no more >> there. >> >> >> >> For your case I can recommend you to take a look at Wro4j. >> >> With this library you can merge all resources which depend on each >> >> other at build time. For production you can even minimize them. >> >> >> > >> > Hi Martin, >> > >> > Assuming I decide not to use wro4j and I want to stick to using Wickets >> > iRequestMapper, is it possible for me to achieve a mapping for resources >> > that I have in webapp dir such as: >> > >> > com.company.Dashboard -> /dashboard >> > >> > Such that if I have a js file in webapp/js/dashboard.js, I can simply map >> > it to resolve to /dashboard/js/dashboard.js instead of >> > /com.company.Dashboard/dashboard.js? >> > >> > While digging further into Wicket >> > ResourceReference/Resourcestream/IRequestMapper/IRequestHandler >> > architecture, I noticed that ResourceReference is designed such that a >> > scope always returns Java package as part of the url to the resource. >> > >> > Using Resourcereference/IRequestMapper, is it possible for me to achieve >> > the scenario I described above? >> > >> > Thanks >> > >> >> >> >> On Mon, Feb 6, 2012 at 4:51 PM, Bertrand Guay-Paquet >> >> <ber...@step.polymtl.ca> wrote: >> >> > Hi, >> >> > >> >> > Thanks for your reply. I'll try to explain why I require this. >> >> > >> >> > I want to use a ResRef to implement dependent resources based on >> >> > AbstractResourceDependentResourceReference. Essentially, when a >> resource >> >> > A.js is added to the response, I want B.js to be also automatically >> >> added. >> >> > >> >> > A.js and B.js are both located in the webapp dir instead of being >> package >> >> > resources. This is why I wanted to make a ResRef point to the webapp >> dir >> >> > directly. >> >> > >> >> > I don't have much experience with Wicket resources so maybe what I >> >> requested >> >> > originally is the wrong tool for the task. >> >> > >> >> > >> >> > On 04/02/2012 5:07 AM, Martin Grigorov wrote: >> >> >> >> >> >> Hi, >> >> >> >> >> >> I didn't understand why you want to use ResRef but if this is your >> >> >> requirement then the easiest will be to create your own >> IRequestMapper >> >> >> that handles only your own IRequestHandler that works with your >> ResRef >> >> >> impl. >> >> >> IRequestMapper#mapHandler(IRequestHandler) is the one responsible to >> >> >> create Url when RequestCycle#urlFor() is used. >> >> >> Also take a look at >> >> >> org.apache.wicket.util.string.UrlUtils#rewriteToContextRelative() >> >> >> >> >> >> On Fri, Feb 3, 2012 at 5:40 PM, Bertrand Guay-Paquet >> >> >> <ber...@step.polymtl.ca> wrote: >> >> >>> >> >> >>> Hi, >> >> >>> >> >> >>> I have the following code in my base page: >> >> >>> >> >> >>> public void renderHead(IHeaderResponse response) { >> >> >>> // scripts/jquery-1.7.1.min.js is in webapp dir >> >> >>> >> response.renderJavaScriptReference("scripts/jquery-1.7.1.min.js"); >> >> >>> } >> >> >>> >> >> >>> How can I transform this direct URL to a ResourceReference? >> >> >>> >> >> >>> PackageResourceReference is not a good fit because I don't want to >> >> store >> >> >>> the >> >> >>> .js in a Java package since it is used by non-wicket pages. >> >> >>> >> >> >>> With ContextRelativeResource, Wicket reads the actual resource and >> >> sends >> >> >>> the >> >> >>> result instead of simply pointing to a URL. >> >> >>> >> >> >>> AbstractResource with its newResourceResponse() abstract method >> >> requires >> >> >>> to >> >> >>> return the actual ResourceResponse which won't allow for a simple >> URL. >> >> >>> >> >> >>> So from what I gather, I would have to fallback to implementing an >> >> >>> IResource's respond(Attributes attributes) method. I looked at the >> >> >>> implementation in AbstractResource but I'm confused about what to do >> >> with >> >> >>> headers since I only want a URL. >> >> >>> >> >> >>> So, does this functionality already exist? If not, do you have a few >> >> >>> pointers to steer me in the right direction? >> >> >>> >> >> >>> Thanks, >> >> >>> Bertrand >> >> >>> >> >> >>> >> --------------------------------------------------------------------- >> >> >>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> >> >>> For additional commands, e-mail: users-h...@wicket.apache.org >> >> >>> >> >> >> >> >> >> >> >> > >> >> > --------------------------------------------------------------------- >> >> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> >> > For additional commands, e-mail: users-h...@wicket.apache.org >> >> > >> >> >> >> >> >> >> >> -- >> >> Martin Grigorov >> >> jWeekend >> >> Training, Consulting, Development >> >> http://jWeekend.com >> >> >> >> --------------------------------------------------------------------- >> >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> >> >> >> > >> > >> > -- >> > Odeyemi 'Kayode O. >> > http://www.sinati.com. t: @charyorde >> >> >> >> -- >> Martin Grigorov >> jWeekend >> Training, Consulting, Development >> http://jWeekend.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > > -- > Odeyemi 'Kayode O. > http://www.sinati.com. t: @charyorde -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org