You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Guillaume Lucazeau <gl...@gmail.com> on 2016/01/06 14:03:49 UTC

Using Sling with a context path

Hello,

I'm trying to use Sling in JBoss, I have installed the war as sling.war and
I'm accessing the web consoles like this : http://localhost:8080/sling

However, I have sevral <sling:include> tags to call different parts of my
web UI (header, footer) as seen in some examples, like this:
<sling:include path="/apps/opal/baseNode" replaceSelectors="header" />

But the context part is missing and therefore the path is wrong and files
are not included. I have the same issue when using resource path in links:
<a href="${resource.path}.html">

I have set this property in sling.properties:

org.apache.felix.http.context_path = /sling

(I can see the value in the Felix console)

 I would just like to know if the context should be automatically
added to the request path (and if yes, how to do so) or if I manually
have to add ${pageContext.request.contextPath} in my JSPs

Thank you very much for your help

Regards,

Guillaume

Re: Using Sling with a context path

Posted by Guillaume Lucazeau <gl...@gmail.com>.
Thank you for confirming that I need to manually set it, I'll stick to the
contextPath property for now and look further at the other resources you've
provided

Thank you for your help
Guillaume

On Thu, Jan 7, 2016 at 10:56 AM, Carsten Ziegeler <cz...@apache.org>
wrote:

> Oliver Lietz wrote
> >
> >>>
> >>> added to the request path (and if yes, how to do so) or if I manually
> >>> have to add ${pageContext.request.contextPath} in my JSPs
> >>
> >> Yes, you need to add the context path for all links going out. You can
> >> either use the way you mention above or use the resourceResolver.map()
> >> functionality.
> >
> > don't do it like above and avoid hardcoding any path which can be changed
> > later. Keep your Sling application portable.
>
> I totally agree that you should not hard code, but neither
> resourceResolver.map() nor using ${pageContext.request.contextPath} in a
> JSP is hard coding. :)
>
> The below mentioned approach of using the rewriter is of course even nicer.
>
> Carsten
>
> >
> > You can use Sling's Rewriter[1] or custom tags or maybe a feature of your
> > template engine or an extension like wcm.io's Link Handler[2] to
> > (post-)process your URLs.
> >
> > Regards,
> > O.
> >
> > [1]
> https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html
> > [2] http://wcm.io/handler/link/
> >
> >> Regards
> >> Carsten
> >>
> >>> Thank you very much for your help
> >>>
> >>> Regards,
> >>>
> >>> Guillaume
> >
> >
>
>
>
> --
> Carsten Ziegeler
> Adobe Research Switzerland
> cziegeler@apache.org
>

Re: Using Sling with a context path

Posted by Carsten Ziegeler <cz...@apache.org>.
Oliver Lietz wrote
>
>>>
>>> added to the request path (and if yes, how to do so) or if I manually
>>> have to add ${pageContext.request.contextPath} in my JSPs
>>
>> Yes, you need to add the context path for all links going out. You can
>> either use the way you mention above or use the resourceResolver.map()
>> functionality.
> 
> don't do it like above and avoid hardcoding any path which can be changed 
> later. Keep your Sling application portable.

I totally agree that you should not hard code, but neither
resourceResolver.map() nor using ${pageContext.request.contextPath} in a
JSP is hard coding. :)

The below mentioned approach of using the rewriter is of course even nicer.

Carsten

> 
> You can use Sling's Rewriter[1] or custom tags or maybe a feature of your 
> template engine or an extension like wcm.io's Link Handler[2] to 
> (post-)process your URLs.
> 
> Regards,
> O.
> 
> [1] https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html
> [2] http://wcm.io/handler/link/
> 
>> Regards
>> Carsten
>>
>>> Thank you very much for your help
>>>
>>> Regards,
>>>
>>> Guillaume
> 
> 


 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org

Re: Using Sling with a context path

Posted by Oliver Lietz <ap...@oliverlietz.de>.
On Wednesday 06 January 2016 16:45:47 Carsten Ziegeler wrote:
> Hi,

Hi,

> Guillaume Lucazeau wrote
> 
> > Hello,
> > 
> > I'm trying to use Sling in JBoss, I have installed the war as sling.war
> > and
> > I'm accessing the web consoles like this : http://localhost:8080/sling
> > 
> > However, I have sevral <sling:include> tags to call different parts of my
> > web UI (header, footer) as seen in some examples, like this:
> > <sling:include path="/apps/opal/baseNode" replaceSelectors="header" />
> 
> this should actually work as this is a resource path which is resolved
> internally.
> 
> > But the context part is missing and therefore the path is wrong and files
> > are not included. I have the same issue when using resource path in links:
> > <a href="${resource.path}.html">
> > 
> > I have set this property in sling.properties:
> > 
> > org.apache.felix.http.context_path = /sling
> > 
> > (I can see the value in the Felix console)
> > 
> >  I would just like to know if the context should be automatically
> > 
> > added to the request path (and if yes, how to do so) or if I manually
> > have to add ${pageContext.request.contextPath} in my JSPs
> 
> Yes, you need to add the context path for all links going out. You can
> either use the way you mention above or use the resourceResolver.map()
> functionality.

don't do it like above and avoid hardcoding any path which can be changed 
later. Keep your Sling application portable.

You can use Sling's Rewriter[1] or custom tags or maybe a feature of your 
template engine or an extension like wcm.io's Link Handler[2] to 
(post-)process your URLs.

Regards,
O.

[1] https://sling.apache.org/documentation/bundles/output-rewriting-pipelines-org-apache-sling-rewriter.html
[2] http://wcm.io/handler/link/

> Regards
> Carsten
> 
> > Thank you very much for your help
> > 
> > Regards,
> > 
> > Guillaume


Re: Using Sling with a context path

Posted by Carsten Ziegeler <cz...@apache.org>.
Hi,


Guillaume Lucazeau wrote
> Hello,
> 
> I'm trying to use Sling in JBoss, I have installed the war as sling.war and
> I'm accessing the web consoles like this : http://localhost:8080/sling
> 
> However, I have sevral <sling:include> tags to call different parts of my
> web UI (header, footer) as seen in some examples, like this:
> <sling:include path="/apps/opal/baseNode" replaceSelectors="header" />

this should actually work as this is a resource path which is resolved
internally.

> 
> But the context part is missing and therefore the path is wrong and files
> are not included. I have the same issue when using resource path in links:
> <a href="${resource.path}.html">
> 
> I have set this property in sling.properties:
> 
> org.apache.felix.http.context_path = /sling
> 
> (I can see the value in the Felix console)
> 
>  I would just like to know if the context should be automatically
> added to the request path (and if yes, how to do so) or if I manually
> have to add ${pageContext.request.contextPath} in my JSPs

Yes, you need to add the context path for all links going out. You can
either use the way you mention above or use the resourceResolver.map()
functionality.

Regards
Carsten

> 
> Thank you very much for your help
> 
> Regards,
> 
> Guillaume
> 


 
-- 
Carsten Ziegeler
Adobe Research Switzerland
cziegeler@apache.org