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 2015/11/17 16:27:25 UTC

Include same comment form from different resource type's views

Hello,

not sure the subject is clear...
I have this simple structure:
- document
-- page(s)
--- component(s) : 1 to 4 on each page

Those components can be of different type : image, text, map, graph. For
each I have a different sling:resourceType for the node and a corresponding
view (JSP)

I'd like to have a form on each component, to allow user to add comments.
They would be created under this path:
/document/pages/page1/components/component1/comments/*

For now I have only two component types: text and image
so in imageComponent/html.jsp I have this:

<sling:include path="${resource.path}" replaceSelectors="comment"/>

and next to html.jsp I have comment.jsp which contains this form: <form
method="POST" action="${resource.path}/comments/*" />

But I have the same in textComponent/. And so far I would have to duplicate
this form for each component type. I'm pretty sure there is a better way to
do it but I don't know how.

Having a specifig resourceType for the comment form would allow me to have
only one, but then I don't know how I could pass the "action" parameter
(e.g. the resource path) to this view.

I bet it's a simple requirement but I didn't find any tips in the document
nor in some examples I've found online.

Thank you for your help!

Regards,
Guillaume

Re: Include same comment form from different resource type's views

Posted by Guillaume Lucazeau <gl...@gmail.com>.
Hello,

I had found this method: <sling:include path="${resource.path}"
resourceType="myapp/commentForm" /> (usually when you post a question you
find the answer right after...) but didn't think about the superType, which
will be useful too.

Many thanks to both of you!
Guillaume

On Tue, Nov 17, 2015 at 9:27 PM, Olaf <ol...@x100.de> wrote:

> Hi Guillaume,
>
> Two more options for you:
>
> You could make a simple file include to the form.jsp (in that case, you
> should name it form.jspf), like so:
>
> <%@include file="/apps/...../form.jspf" %>
>
>
> You could also include the same resource with a different resource type,
> thus rendering a different view for it, like so:
>
> <sling:include path="${resource.path}" resourceType="myapp/commentForm" />
>
> Here, /apps/myapp/commentForm would be your form component. This approach
> would be composition instead of inheritance.
>
> However, the inheritance suggested by Stefan allows overriding the
> form.jsp in you subtypes, which might be handy.
>
> Regards,
> Olaf
>
> -----Original Message-----
> From: Stefan Seifert [mailto:sseifert@pro-vision.de]
> Sent: Dienstag, 17. November 2015 17:30
> To: users@sling.apache.org
> Subject: RE: Include same comment form from different resource type's views
>
> hello guillaume.
>
> a typical solution is to define another "common" resource types for your
> components and reference it as "sling:resourceSuperType", see [1], [2]
>
> then you can move your comment.jsp to the folder of the "common" resource
> type and it is usable from all components inheriting from this.
>
> stefan
>
>
> [1]
> https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#base-resource-type-inheritance
> [2]
> http://stackoverflow.com/questions/22708055/how-does-apache-sling-script-resolving-rules-work
>
>
> >-----Original Message-----
> >From: Guillaume Lucazeau [mailto:glucazeau@gmail.com]
> >Sent: Tuesday, November 17, 2015 4:27 PM
> >To: users@sling.apache.org
> >Subject: Include same comment form from different resource type's views
> >
> >Hello,
> >
> >not sure the subject is clear...
> >I have this simple structure:
> >- document
> >-- page(s)
> >--- component(s) : 1 to 4 on each page
> >
> >Those components can be of different type : image, text, map, graph.
> >For each I have a different sling:resourceType for the node and a
> >corresponding view (JSP)
> >
> >I'd like to have a form on each component, to allow user to add comments.
> >They would be created under this path:
> >/document/pages/page1/components/component1/comments/*
> >
> >For now I have only two component types: text and image so in
> >imageComponent/html.jsp I have this:
> >
> ><sling:include path="${resource.path}" replaceSelectors="comment"/>
> >
> >and next to html.jsp I have comment.jsp which contains this form: <form
> >method="POST" action="${resource.path}/comments/*" />
> >
> >But I have the same in textComponent/. And so far I would have to
> >duplicate this form for each component type. I'm pretty sure there is a
> >better way to do it but I don't know how.
> >
> >Having a specifig resourceType for the comment form would allow me to
> >have only one, but then I don't know how I could pass the "action"
> >parameter (e.g. the resource path) to this view.
> >
> >I bet it's a simple requirement but I didn't find any tips in the
> >document nor in some examples I've found online.
> >
> >Thank you for your help!
> >
> >Regards,
> >Guillaume
>
>

RE: Include same comment form from different resource type's views

Posted by Olaf <ol...@x100.de>.
Hi Guillaume,

Two more options for you:

You could make a simple file include to the form.jsp (in that case, you should name it form.jspf), like so:

<%@include file="/apps/...../form.jspf" %>


You could also include the same resource with a different resource type, thus rendering a different view for it, like so:

<sling:include path="${resource.path}" resourceType="myapp/commentForm" />

Here, /apps/myapp/commentForm would be your form component. This approach would be composition instead of inheritance.

However, the inheritance suggested by Stefan allows overriding the form.jsp in you subtypes, which might be handy.

Regards,
Olaf

-----Original Message-----
From: Stefan Seifert [mailto:sseifert@pro-vision.de] 
Sent: Dienstag, 17. November 2015 17:30
To: users@sling.apache.org
Subject: RE: Include same comment form from different resource type's views

hello guillaume.

a typical solution is to define another "common" resource types for your components and reference it as "sling:resourceSuperType", see [1], [2]

then you can move your comment.jsp to the folder of the "common" resource type and it is usable from all components inheriting from this.

stefan


[1] https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#base-resource-type-inheritance
[2] http://stackoverflow.com/questions/22708055/how-does-apache-sling-script-resolving-rules-work


>-----Original Message-----
>From: Guillaume Lucazeau [mailto:glucazeau@gmail.com]
>Sent: Tuesday, November 17, 2015 4:27 PM
>To: users@sling.apache.org
>Subject: Include same comment form from different resource type's views
>
>Hello,
>
>not sure the subject is clear...
>I have this simple structure:
>- document
>-- page(s)
>--- component(s) : 1 to 4 on each page
>
>Those components can be of different type : image, text, map, graph. 
>For each I have a different sling:resourceType for the node and a 
>corresponding view (JSP)
>
>I'd like to have a form on each component, to allow user to add comments.
>They would be created under this path:
>/document/pages/page1/components/component1/comments/*
>
>For now I have only two component types: text and image so in 
>imageComponent/html.jsp I have this:
>
><sling:include path="${resource.path}" replaceSelectors="comment"/>
>
>and next to html.jsp I have comment.jsp which contains this form: <form 
>method="POST" action="${resource.path}/comments/*" />
>
>But I have the same in textComponent/. And so far I would have to 
>duplicate this form for each component type. I'm pretty sure there is a 
>better way to do it but I don't know how.
>
>Having a specifig resourceType for the comment form would allow me to 
>have only one, but then I don't know how I could pass the "action" 
>parameter (e.g. the resource path) to this view.
>
>I bet it's a simple requirement but I didn't find any tips in the 
>document nor in some examples I've found online.
>
>Thank you for your help!
>
>Regards,
>Guillaume


RE: Include same comment form from different resource type's views

Posted by Stefan Seifert <ss...@pro-vision.de>.
hello guillaume.

a typical solution is to define another "common" resource types for your components and reference it as "sling:resourceSuperType", see [1], [2]

then you can move your comment.jsp to the folder of the "common" resource type and it is usable from all components inheriting from this.

stefan


[1] https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#base-resource-type-inheritance
[2] http://stackoverflow.com/questions/22708055/how-does-apache-sling-script-resolving-rules-work


>-----Original Message-----
>From: Guillaume Lucazeau [mailto:glucazeau@gmail.com]
>Sent: Tuesday, November 17, 2015 4:27 PM
>To: users@sling.apache.org
>Subject: Include same comment form from different resource type's views
>
>Hello,
>
>not sure the subject is clear...
>I have this simple structure:
>- document
>-- page(s)
>--- component(s) : 1 to 4 on each page
>
>Those components can be of different type : image, text, map, graph. For
>each I have a different sling:resourceType for the node and a corresponding
>view (JSP)
>
>I'd like to have a form on each component, to allow user to add comments.
>They would be created under this path:
>/document/pages/page1/components/component1/comments/*
>
>For now I have only two component types: text and image
>so in imageComponent/html.jsp I have this:
>
><sling:include path="${resource.path}" replaceSelectors="comment"/>
>
>and next to html.jsp I have comment.jsp which contains this form: <form
>method="POST" action="${resource.path}/comments/*" />
>
>But I have the same in textComponent/. And so far I would have to duplicate
>this form for each component type. I'm pretty sure there is a better way to
>do it but I don't know how.
>
>Having a specifig resourceType for the comment form would allow me to have
>only one, but then I don't know how I could pass the "action" parameter
>(e.g. the resource path) to this view.
>
>I bet it's a simple requirement but I didn't find any tips in the document
>nor in some examples I've found online.
>
>Thank you for your help!
>
>Regards,
>Guillaume