You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Marco Dohnke <ma...@valtech.de> on 2011/03/31 13:49:55 UTC

Inheritance and URL decomposition

Hi,

I created two (CQ5.4) components 'page' and 'product'. I want to inherit product from page and overwrite i.e. the center.jsp of the page component. I also want to make sure you can call two 'views' of the product component. Therefore I tried to use a selector:

/products/my-first-product.html -> renders default script
/products/my-first-product.simple.html -> renders a more simple version

If I use a simple.jsp, Sling is calling this script, but I lose the inheritance (not DRY). Is there any chance to use both? I want to inherit some parts of the page component, other parts shall be overwritten. How can I realize this?

Kind regards,
Marco

AW: Inheritance and URL decomposition

Posted by Marco Dohnke <ma...@valtech.de>.
Thanks for your answer. I thought it is more a Sling question cause Sling resolves the types. But I will try it on the CQ list...

Kind regards

-----Ursprüngliche Nachricht-----
Von: sam lee [mailto:skynare@gmail.com] 
Gesendet: Donnerstag, 31. März 2011 15:41
An: users@sling.apache.org
Betreff: Re: Inheritance and URL decomposition

Day CQ mailing list is: http://groups.google.com/group/day-communique

If the resource, /products/my-first-product ,  has sling:resourceType =
/apps/foo/product,
then, to render .html version of the resource,  /apps/foo/product/html.jsp
will be used.
To render simple.html version of the resource,
/apps/foo/product/simple.html.jsp will be used.

You can do whatever you want in those .jsp files.

I am not sure about inheritance.
You can set /products/my-first-product's  sling:resourceSuperType =
/apps/foo/page ..
But I am not sure if that will help for your script resolution (using
<sling:include/>).

Since you are using CQ,  you may want to look at <cq:include/>.


On Thu, Mar 31, 2011 at 7:49 AM, Marco Dohnke <ma...@valtech.de>wrote:

> Hi,
>
> I created two (CQ5.4) components 'page' and 'product'. I want to inherit
> product from page and overwrite i.e. the center.jsp of the page component. I
> also want to make sure you can call two 'views' of the product component.
> Therefore I tried to use a selector:
>
> /products/my-first-product.html -> renders default script
> /products/my-first-product.simple.html -> renders a more simple version
>
> If I use a simple.jsp, Sling is calling this script, but I lose the
> inheritance (not DRY). Is there any chance to use both? I want to inherit
> some parts of the page component, other parts shall be overwritten. How can
> I realize this?
>
> Kind regards,
> Marco
>

Re: AW: Inheritance and URL decomposition

Posted by Alexander Klimetschek <ak...@adobe.com>.
What tag exactly do you use to do the include? Because there is an
important difference in <cq:include script="foo.jsp" /> compared to
<cq/sling:include path="foo" />.

cq:include with script will look up the script by name directly instead of
using the resource type/selector/extension resolution (albeit it does
handle rt inheritance).

Regards,
Alex

On 01.04.11 10:02, "Marco Dohnke" <ma...@valtech.de> wrote:

>Thanks for your answers. Both sound quite interesting. I will check them
>although JSPs are not my first choice too. Because I didn't found an
>alternative yet, I am also interested in new ideas.
>
>-----Ursprüngliche Nachricht-----
>Von: sam lee [mailto:skynare@gmail.com]
>Gesendet: Freitag, 1. April 2011 15:30
>An: users@sling.apache.org
>Betreff: Re: Inheritance and URL decomposition
>
>I think he really means <cq:include/>.
>
>/apps/component/page
>/apps/component/page/head.jsp
>/apps/component/page/body.jsp
>/apps/component/page/center.jsp
>...
>/apps/component/page/html.jsp
>
>And, in html.jsp, you do:
><cq:include script="center.jsp"/>
>
>
>And, you have:
>/apps/component/product  @sling:resourceSuperType = component/page
>/apps/component/product/center.jsp
>/apps/component/product/simple.html.jsp
>
>And, in simple.html.jsp, you do:
><cq:include script="html.jsp"/>
>
>Then, I think component/page/html.jsp will be included since you did not
>overwrote it in component/product.
>And, the html.jsp in turn will include center.jsp.. and since center.jsp
>is
>overwritten, product/center.jsp will be used.
>
>But that's CQ stuff.
>
>In sling, you'll have to write your own taglib that does that. I am not
>sure
>if <cq:include/> is open source.
>
>But seriously... I would want to move away from jsp and use a proper html
>templating.
>Has anyone done this?
>
>
>
>
>On Fri, Apr 1, 2011 at 9:21 AM, Justin Edelson
><ju...@justinedelson.com>wrote:
>
>> Depending on the scope of the change between the regular and "simple"
>> views, one thing you could do is just have an if statement in your
>> center.jsp which does something like this:
>>
>> <% if ("simple".equals(slingRequest.getSelectorString()) { %>
>> <!-- do the simple thing -->
>> <% } else { %>
>> <!-- do the non-simple thing -->
>> <% } %>
>>
>> Within the if / else blocks, you could include other scripts of course.
>>
>> HTH,
>> Justin
>>
>> On Fri, Apr 1, 2011 at 5:27 AM, Marco Dohnke <ma...@valtech.de>
>> wrote:
>> > Yes I know. I also tried several ways with the resourceSuperType. The
>> problem is:
>> >
>> > /apps/myapp/components/product/center.jsp overwrites
>> /apps/myapp/components/page/center.jsp because the resourceSuperType is
>>set
>> on it.
>> >
>> > But a sling selector is not useable for that. If I use
>> /apps/.../product/simple.jsp I have to reimplement all what I
>>implemented in
>> the page component. That's not very DRY. I thought there is a way to
>>achieve
>> this.
>> >
>> > Kind regards,
>> > Marco
>> >
>> > -----Ursprüngliche Nachricht-----
>> > Von: Felix Meschberger [mailto:fmeschbe@adobe.com]
>> > Gesendet: Freitag, 1. April 2011 10:50
>> > An: users@sling.apache.org
>> > Betreff: Re: Inheritance and URL decomposition
>> >
>> > Hi,
>> >
>> > Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee:
>> >> Day CQ mailing list is: http://groups.google.com/group/day-communique
>> >>
>> >> If the resource, /products/my-first-product ,  has
>>sling:resourceType =
>> >> /apps/foo/product,
>> >> then, to render .html version of the resource,
>>  /apps/foo/product/html.jsp
>> >> will be used.
>> >> To render simple.html version of the resource,
>> >> /apps/foo/product/simple.html.jsp will be used.
>> >>
>> >> You can do whatever you want in those .jsp files.
>> >>
>> >> I am not sure about inheritance.
>> >> You can set /products/my-first-product's  sling:resourceSuperType =
>> >> /apps/foo/page ..
>> >> But I am not sure if that will help for your script resolution (using
>> >> <sling:include/>).
>> >
>> > Yes, sling supports sling:resourceSuperType of course and thus all
>> > resolutions for scripts and servlets will check the resource type
>> > hierarchy.
>> >
>> > Regards
>> > Felix
>> >
>> >
>> >
>>
>


-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel


AW: Inheritance and URL decomposition

Posted by Marco Dohnke <ma...@valtech.de>.
Thanks for your answers. Both sound quite interesting. I will check them although JSPs are not my first choice too. Because I didn't found an alternative yet, I am also interested in new ideas.

-----Ursprüngliche Nachricht-----
Von: sam lee [mailto:skynare@gmail.com] 
Gesendet: Freitag, 1. April 2011 15:30
An: users@sling.apache.org
Betreff: Re: Inheritance and URL decomposition

I think he really means <cq:include/>.

/apps/component/page
/apps/component/page/head.jsp
/apps/component/page/body.jsp
/apps/component/page/center.jsp
...
/apps/component/page/html.jsp

And, in html.jsp, you do:
<cq:include script="center.jsp"/>


And, you have:
/apps/component/product  @sling:resourceSuperType = component/page
/apps/component/product/center.jsp
/apps/component/product/simple.html.jsp

And, in simple.html.jsp, you do:
<cq:include script="html.jsp"/>

Then, I think component/page/html.jsp will be included since you did not
overwrote it in component/product.
And, the html.jsp in turn will include center.jsp.. and since center.jsp is
overwritten, product/center.jsp will be used.

But that's CQ stuff.

In sling, you'll have to write your own taglib that does that. I am not sure
if <cq:include/> is open source.

But seriously... I would want to move away from jsp and use a proper html
templating.
Has anyone done this?




On Fri, Apr 1, 2011 at 9:21 AM, Justin Edelson <ju...@justinedelson.com>wrote:

> Depending on the scope of the change between the regular and "simple"
> views, one thing you could do is just have an if statement in your
> center.jsp which does something like this:
>
> <% if ("simple".equals(slingRequest.getSelectorString()) { %>
> <!-- do the simple thing -->
> <% } else { %>
> <!-- do the non-simple thing -->
> <% } %>
>
> Within the if / else blocks, you could include other scripts of course.
>
> HTH,
> Justin
>
> On Fri, Apr 1, 2011 at 5:27 AM, Marco Dohnke <ma...@valtech.de>
> wrote:
> > Yes I know. I also tried several ways with the resourceSuperType. The
> problem is:
> >
> > /apps/myapp/components/product/center.jsp overwrites
> /apps/myapp/components/page/center.jsp because the resourceSuperType is set
> on it.
> >
> > But a sling selector is not useable for that. If I use
> /apps/.../product/simple.jsp I have to reimplement all what I implemented in
> the page component. That's not very DRY. I thought there is a way to achieve
> this.
> >
> > Kind regards,
> > Marco
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Felix Meschberger [mailto:fmeschbe@adobe.com]
> > Gesendet: Freitag, 1. April 2011 10:50
> > An: users@sling.apache.org
> > Betreff: Re: Inheritance and URL decomposition
> >
> > Hi,
> >
> > Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee:
> >> Day CQ mailing list is: http://groups.google.com/group/day-communique
> >>
> >> If the resource, /products/my-first-product ,  has sling:resourceType =
> >> /apps/foo/product,
> >> then, to render .html version of the resource,
>  /apps/foo/product/html.jsp
> >> will be used.
> >> To render simple.html version of the resource,
> >> /apps/foo/product/simple.html.jsp will be used.
> >>
> >> You can do whatever you want in those .jsp files.
> >>
> >> I am not sure about inheritance.
> >> You can set /products/my-first-product's  sling:resourceSuperType =
> >> /apps/foo/page ..
> >> But I am not sure if that will help for your script resolution (using
> >> <sling:include/>).
> >
> > Yes, sling supports sling:resourceSuperType of course and thus all
> > resolutions for scripts and servlets will check the resource type
> > hierarchy.
> >
> > Regards
> > Felix
> >
> >
> >
>

Re: Inheritance and URL decomposition

Posted by sam lee <sk...@gmail.com>.
I think he really means <cq:include/>.

/apps/component/page
/apps/component/page/head.jsp
/apps/component/page/body.jsp
/apps/component/page/center.jsp
...
/apps/component/page/html.jsp

And, in html.jsp, you do:
<cq:include script="center.jsp"/>


And, you have:
/apps/component/product  @sling:resourceSuperType = component/page
/apps/component/product/center.jsp
/apps/component/product/simple.html.jsp

And, in simple.html.jsp, you do:
<cq:include script="html.jsp"/>

Then, I think component/page/html.jsp will be included since you did not
overwrote it in component/product.
And, the html.jsp in turn will include center.jsp.. and since center.jsp is
overwritten, product/center.jsp will be used.

But that's CQ stuff.

In sling, you'll have to write your own taglib that does that. I am not sure
if <cq:include/> is open source.

But seriously... I would want to move away from jsp and use a proper html
templating.
Has anyone done this?




On Fri, Apr 1, 2011 at 9:21 AM, Justin Edelson <ju...@justinedelson.com>wrote:

> Depending on the scope of the change between the regular and "simple"
> views, one thing you could do is just have an if statement in your
> center.jsp which does something like this:
>
> <% if ("simple".equals(slingRequest.getSelectorString()) { %>
> <!-- do the simple thing -->
> <% } else { %>
> <!-- do the non-simple thing -->
> <% } %>
>
> Within the if / else blocks, you could include other scripts of course.
>
> HTH,
> Justin
>
> On Fri, Apr 1, 2011 at 5:27 AM, Marco Dohnke <ma...@valtech.de>
> wrote:
> > Yes I know. I also tried several ways with the resourceSuperType. The
> problem is:
> >
> > /apps/myapp/components/product/center.jsp overwrites
> /apps/myapp/components/page/center.jsp because the resourceSuperType is set
> on it.
> >
> > But a sling selector is not useable for that. If I use
> /apps/.../product/simple.jsp I have to reimplement all what I implemented in
> the page component. That's not very DRY. I thought there is a way to achieve
> this.
> >
> > Kind regards,
> > Marco
> >
> > -----Ursprüngliche Nachricht-----
> > Von: Felix Meschberger [mailto:fmeschbe@adobe.com]
> > Gesendet: Freitag, 1. April 2011 10:50
> > An: users@sling.apache.org
> > Betreff: Re: Inheritance and URL decomposition
> >
> > Hi,
> >
> > Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee:
> >> Day CQ mailing list is: http://groups.google.com/group/day-communique
> >>
> >> If the resource, /products/my-first-product ,  has sling:resourceType =
> >> /apps/foo/product,
> >> then, to render .html version of the resource,
>  /apps/foo/product/html.jsp
> >> will be used.
> >> To render simple.html version of the resource,
> >> /apps/foo/product/simple.html.jsp will be used.
> >>
> >> You can do whatever you want in those .jsp files.
> >>
> >> I am not sure about inheritance.
> >> You can set /products/my-first-product's  sling:resourceSuperType =
> >> /apps/foo/page ..
> >> But I am not sure if that will help for your script resolution (using
> >> <sling:include/>).
> >
> > Yes, sling supports sling:resourceSuperType of course and thus all
> > resolutions for scripts and servlets will check the resource type
> > hierarchy.
> >
> > Regards
> > Felix
> >
> >
> >
>

Re: Inheritance and URL decomposition

Posted by Justin Edelson <ju...@justinedelson.com>.
Depending on the scope of the change between the regular and "simple"
views, one thing you could do is just have an if statement in your
center.jsp which does something like this:

<% if ("simple".equals(slingRequest.getSelectorString()) { %>
<!-- do the simple thing -->
<% } else { %>
<!-- do the non-simple thing -->
<% } %>

Within the if / else blocks, you could include other scripts of course.

HTH,
Justin

On Fri, Apr 1, 2011 at 5:27 AM, Marco Dohnke <ma...@valtech.de> wrote:
> Yes I know. I also tried several ways with the resourceSuperType. The problem is:
>
> /apps/myapp/components/product/center.jsp overwrites /apps/myapp/components/page/center.jsp because the resourceSuperType is set on it.
>
> But a sling selector is not useable for that. If I use /apps/.../product/simple.jsp I have to reimplement all what I implemented in the page component. That's not very DRY. I thought there is a way to achieve this.
>
> Kind regards,
> Marco
>
> -----Ursprüngliche Nachricht-----
> Von: Felix Meschberger [mailto:fmeschbe@adobe.com]
> Gesendet: Freitag, 1. April 2011 10:50
> An: users@sling.apache.org
> Betreff: Re: Inheritance and URL decomposition
>
> Hi,
>
> Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee:
>> Day CQ mailing list is: http://groups.google.com/group/day-communique
>>
>> If the resource, /products/my-first-product ,  has sling:resourceType =
>> /apps/foo/product,
>> then, to render .html version of the resource,  /apps/foo/product/html.jsp
>> will be used.
>> To render simple.html version of the resource,
>> /apps/foo/product/simple.html.jsp will be used.
>>
>> You can do whatever you want in those .jsp files.
>>
>> I am not sure about inheritance.
>> You can set /products/my-first-product's  sling:resourceSuperType =
>> /apps/foo/page ..
>> But I am not sure if that will help for your script resolution (using
>> <sling:include/>).
>
> Yes, sling supports sling:resourceSuperType of course and thus all
> resolutions for scripts and servlets will check the resource type
> hierarchy.
>
> Regards
> Felix
>
>
>

AW: Inheritance and URL decomposition

Posted by Marco Dohnke <ma...@valtech.de>.
Yes I know. I also tried several ways with the resourceSuperType. The problem is:

/apps/myapp/components/product/center.jsp overwrites /apps/myapp/components/page/center.jsp because the resourceSuperType is set on it.

But a sling selector is not useable for that. If I use /apps/.../product/simple.jsp I have to reimplement all what I implemented in the page component. That's not very DRY. I thought there is a way to achieve this.

Kind regards,
Marco

-----Ursprüngliche Nachricht-----
Von: Felix Meschberger [mailto:fmeschbe@adobe.com] 
Gesendet: Freitag, 1. April 2011 10:50
An: users@sling.apache.org
Betreff: Re: Inheritance and URL decomposition

Hi,

Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee: 
> Day CQ mailing list is: http://groups.google.com/group/day-communique
> 
> If the resource, /products/my-first-product ,  has sling:resourceType =
> /apps/foo/product,
> then, to render .html version of the resource,  /apps/foo/product/html.jsp
> will be used.
> To render simple.html version of the resource,
> /apps/foo/product/simple.html.jsp will be used.
> 
> You can do whatever you want in those .jsp files.
> 
> I am not sure about inheritance.
> You can set /products/my-first-product's  sling:resourceSuperType =
> /apps/foo/page ..
> But I am not sure if that will help for your script resolution (using
> <sling:include/>).

Yes, sling supports sling:resourceSuperType of course and thus all
resolutions for scripts and servlets will check the resource type
hierarchy.

Regards
Felix



Re: Inheritance and URL decomposition

Posted by Felix Meschberger <fm...@adobe.com>.
Hi,

Am Donnerstag, den 31.03.2011, 14:41 +0100 schrieb sam lee: 
> Day CQ mailing list is: http://groups.google.com/group/day-communique
> 
> If the resource, /products/my-first-product ,  has sling:resourceType =
> /apps/foo/product,
> then, to render .html version of the resource,  /apps/foo/product/html.jsp
> will be used.
> To render simple.html version of the resource,
> /apps/foo/product/simple.html.jsp will be used.
> 
> You can do whatever you want in those .jsp files.
> 
> I am not sure about inheritance.
> You can set /products/my-first-product's  sling:resourceSuperType =
> /apps/foo/page ..
> But I am not sure if that will help for your script resolution (using
> <sling:include/>).

Yes, sling supports sling:resourceSuperType of course and thus all
resolutions for scripts and servlets will check the resource type
hierarchy.

Regards
Felix


Re: Inheritance and URL decomposition

Posted by sam lee <sk...@gmail.com>.
Day CQ mailing list is: http://groups.google.com/group/day-communique

If the resource, /products/my-first-product ,  has sling:resourceType =
/apps/foo/product,
then, to render .html version of the resource,  /apps/foo/product/html.jsp
will be used.
To render simple.html version of the resource,
/apps/foo/product/simple.html.jsp will be used.

You can do whatever you want in those .jsp files.

I am not sure about inheritance.
You can set /products/my-first-product's  sling:resourceSuperType =
/apps/foo/page ..
But I am not sure if that will help for your script resolution (using
<sling:include/>).

Since you are using CQ,  you may want to look at <cq:include/>.


On Thu, Mar 31, 2011 at 7:49 AM, Marco Dohnke <ma...@valtech.de>wrote:

> Hi,
>
> I created two (CQ5.4) components 'page' and 'product'. I want to inherit
> product from page and overwrite i.e. the center.jsp of the page component. I
> also want to make sure you can call two 'views' of the product component.
> Therefore I tried to use a selector:
>
> /products/my-first-product.html -> renders default script
> /products/my-first-product.simple.html -> renders a more simple version
>
> If I use a simple.jsp, Sling is calling this script, but I lose the
> inheritance (not DRY). Is there any chance to use both? I want to inherit
> some parts of the page component, other parts shall be overwritten. How can
> I realize this?
>
> Kind regards,
> Marco
>