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:sseif...@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:glucaz...@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

Reply via email to