Re: Overridable css resource

2011-12-26 Thread Serban Balamaci
Hi Martin,
That's a good solution, currently I keep the response.renderCSSReference(new
CustomCssResourceReference("front.css")) but implement a custom
DecoratingHeaderResponse to chose if I return instead of the string the
original packaged css resource in the war file.

DecoratingHeaderResponse 
public void renderCSSReference(ResourceReference reference) {
if(reference.getScope()) and if the css file is available do a
super.renderCSS(reference.getName()) and if not return a new
CssResourceReference(reference.getScope(), reference.getName())


However I was not fully confident about this approach of rendering the css
string, because Wicket cannot apply the caching strategy addition of a
IStaticCacheableResource.

Right now I mounted a that takes the name of the resource from the url.
app.mountResource("/custom/css/${name}", new CustomDirResourceReference());
to solve any requests for /custom/css/front.css

but also have a custom ResourceReferenceRegistry that automatically creates
the ResourceReference for CustomCssResourceReferences:
protected ResourceReferenceRegistry newResourceReferenceRegistry() {
return new ResourceReferenceRegistry() {
@Override
protected ResourceReference
createDefaultResourceReference(ResourceReference.Key key) {
if(key.getScope().equals(CustomCssResource.class.getName()))
{
return new CustomCssResourceReference(key.getName());
}
return super.createDefaultResourceReference(key);
}
};
}

I only need to solve the fact that it mounts it to a package
wicket/resource/com.dada.web.frontend.resource.CustomCssResource/front-ver-1324746271000.css
and not to a "nice" url perhaps something like
getSharedResources().putClassAlias()

-
http://balamaci.wordpress.com 
--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Overridable-css-resource-tp4229370p4235219.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Overridable css resource

2011-12-26 Thread Martin Grigorov
Hi,

See http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/
There I used following code for this:

 ResourceReference imagesResourceReference = new ImageResourceReference();
 PageParameters imageParameters = new PageParameters();

 String imageName = "anyName.jpg";
 imageParameters.set("name", imageName);
 CharSequence urlForImage =
getRequestCycle().urlFor(imagesResourceReference, imageParameters);
 ExternalLink link = new ExternalLink("link", urlForImage.toString());

I.e. you can create the url as string, then instead of
renderCssResRef() use renderCss(String url)

On Fri, Dec 23, 2011 at 7:54 PM, Serban Balamaci  wrote:
> Hi all,
> I'm trying to serve some css files from a custom dir outside the  web dir.
> It should get a little more complicated that I'd want to fallback to serve
> the file from a package location if it's not found in the custom-css folder,
> but let's keep it simple first.
>
> I've created a class
> public class CustomCssResource extends AbstractResource implements
> IStaticCacheableResource {
>    public CustomCssResource(String path) {
>        this.path = path;
> }
> ...
> }
> that returns the css file found at path location.
>
> And public class CustomCssResourceReference extends ResourceReference {
> public CustomCssResourceReference(String name) {
> super(scope, "custom-css-dir/" + name);
> }
> public IResource getResource() {
> return new CustomCssResource(name);
> }
> }
>
> In pages I do something like this:
> response.renderCSSReference(new CustomCssResourceReference("front.css"));
>
> Problem is that I'd want to mount this serving of resources from
> "/customcss"
> But how should this be done? Because I cannot just do
> app.mountResource("/customcss", new CustomCssResourceReference("???"));
>
> Should I bind as SharedResources all css files instead of using
> CustomCssResourceReference?
>
> Thanks.
>
> -
> http://balamaci.wordpress.com
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/Overridable-css-resource-tp4229370p4229370.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> 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



Overridable css resource

2011-12-23 Thread Serban Balamaci
Hi all,
I'm trying to serve some css files from a custom dir outside the  web dir.
It should get a little more complicated that I'd want to fallback to serve
the file from a package location if it's not found in the custom-css folder,
but let's keep it simple first.

I've created a class
public class CustomCssResource extends AbstractResource implements
IStaticCacheableResource {
public CustomCssResource(String path) {
this.path = path;
}
...
} 
that returns the css file found at path location.

And public class CustomCssResourceReference extends ResourceReference {
public CustomCssResourceReference(String name) {
super(scope, "custom-css-dir/" + name);
}
public IResource getResource() {
return new CustomCssResource(name);
}
}

In pages I do something like this:
response.renderCSSReference(new CustomCssResourceReference("front.css"));

Problem is that I'd want to mount this serving of resources from
"/customcss"
But how should this be done? Because I cannot just do 
app.mountResource("/customcss", new CustomCssResourceReference("???"));

Should I bind as SharedResources all css files instead of using
CustomCssResourceReference?

Thanks.

-
http://balamaci.wordpress.com 
--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Overridable-css-resource-tp4229370p4229370.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org