You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gianni Doe <gd...@yahoo.it> on 2008/10/21 10:18:45 UTC

ContextImage not generating path relative to context root

I'm a bit confused about ContextImage; according to the javadocs the  
image path "will be prefixed such that the image is relative to the  
context root".

In my markup I've got:
<img wicket:id="logo" src="mylogo.gif" />

Then I add the Context image to my WebPage:
add(new ContextImage("logo", "images/logos/mylogo.gif"));

... and I end up with:
<img src="../images/logos/mylogo.gif" />

My application is deployed with a context root of /myapp and this  
doesn't work, it will only work if the application is deployed with a  
context root of /. I've checked the source which ContextImage uses to  
get the context root and in org.apache.wicket.Request it says:

/**
  * Gets a prefix to make this relative to the context root.
  * <p>
  * For example, if your context root is http://server.com/myApp/ and  
the request is for
  * /myApp/mountedPage/, then the prefix returned might be "../../".
  * <p>
  * For a particular technology, this might return either an absolute  
prefix or a relative one.
  *
  * @return Prefix relative to this request required to back up to  
context root.
  */
public abstract String getRelativePathPrefixToContextRoot();

To me this just seems plain wrong, here it clearly states that the  
context root is "http://server.com/myApp/" but the example prefix of  
"../../" relative to "/myApp/mountedPage/" does not take you to the  
context root of /myApp/ but to /.

This is very confusing as I've always considered the context root of a  
java web application to to be the path upon which it is deployed on  
the application server, whether that be /, /myApp or /apps/myApp and  
in the above case I do not end up with an image path relative to the  
context root.
Without hard-coding the name of my context root in the image path (bad  
idea for portability) how can I reference static images stored in an  
images directory under the context root?

Should I file this as a bug or am I missing something?
Thanks
Gianni




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


Re: ContextImage not generating path relative to context root

Posted by Matej Knopp <ma...@gmail.com>.
Al, do you have any idea?

-Matej

On Tue, Oct 21, 2008 at 10:18 AM, Gianni Doe <gd...@yahoo.it> wrote:
> I'm a bit confused about ContextImage; according to the javadocs the image
> path "will be prefixed such that the image is relative to the context root".
>
> In my markup I've got:
> <img wicket:id="logo" src="mylogo.gif" />
>
> Then I add the Context image to my WebPage:
> add(new ContextImage("logo", "images/logos/mylogo.gif"));
>
> ... and I end up with:
> <img src="../images/logos/mylogo.gif" />
>
> My application is deployed with a context root of /myapp and this doesn't
> work, it will only work if the application is deployed with a context root
> of /. I've checked the source which ContextImage uses to get the context
> root and in org.apache.wicket.Request it says:
>
> /**
>  * Gets a prefix to make this relative to the context root.
>  * <p>
>  * For example, if your context root is http://server.com/myApp/ and the
> request is for
>  * /myApp/mountedPage/, then the prefix returned might be "../../".
>  * <p>
>  * For a particular technology, this might return either an absolute prefix
> or a relative one.
>  *
>  * @return Prefix relative to this request required to back up to context
> root.
>  */
> public abstract String getRelativePathPrefixToContextRoot();
>
> To me this just seems plain wrong, here it clearly states that the context
> root is "http://server.com/myApp/" but the example prefix of "../../"
> relative to "/myApp/mountedPage/" does not take you to the context root of
> /myApp/ but to /.
>
> This is very confusing as I've always considered the context root of a java
> web application to to be the path upon which it is deployed on the
> application server, whether that be /, /myApp or /apps/myApp and in the
> above case I do not end up with an image path relative to the context root.
> Without hard-coding the name of my context root in the image path (bad idea
> for portability) how can I reference static images stored in an images
> directory under the context root?
>
> Should I file this as a bug or am I missing something?
> Thanks
> Gianni
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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