You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by Rory Douglas <ro...@oracle.com> on 2008/07/28 21:12:16 UTC
Node creation form best practice
I have registered a couple of custom nodetypes with corresponding
rendering scripts html.jsp in the appropriate folder. Now I'd like to
include a few simple forms to create that node type (re-using as much
existing functionality as possible). What is the best way to do this?
I had a few ideas: (assume I have a nodetype test:Widget with a display
script /apps/test/Widget/html.jsp)
1) Create "form" nodes (/forms/Widget/create)
a) use sling:resourceType="form:Widget"
b) register a script /apps/form/Widget/html.jsp that generates an
HTML form (and uses the SlingPostServlet to create the content)
2) Create an "empty" Widget node (/content/Widget/new)
a) use jcr:primaryResourceType="test:Widget"
b) register a script with a "create" selector
apps/test/Widget/create.html.jsp that generates the HTML form
I assume I could also register new servlets by paths, and then either
directly create content or somehow forward to the SlingPostServlet. In
all cases where I use the SlingPostServlet, what's the best way to
handle failures or errors?
Re: Node creation form best practice
Posted by Lars Trieloff <la...@day.com>.
Hi Rory,
try setting the jcr:mimeType property of the /forms/widgets/
createNewWidget.html/jcr:content node to text/html. This should do the
trick.
If you want to have a JSP that just executes, try to create a dummy
content node with a sling:resourceType that points to your JSP file.
regards,
Lars
On 28.07.2008, at 22:16, Rory Douglas wrote:
> Thanks Toby
>
> I guess my question is even simpler then - where do you store those
> forms? I've tried uploading .HTML forms to the repository:
>
> curl -X PUT -d @createNewWidget.html "http://admin:admin@localhost:8888/forms/widgets/createNewWidget.html
> "
>
> When I request that path (/forms/widgets/createNewWidget.html), my
> browser tries to download me the source rather than display the
> HTML. I assume I need to add some kind of contentType attribute
> when I upload the form, I'll look into that.
>
> Also, how would I deploy a dynamic form (say, JSP-based), that might
> configure it's display, default values etc differently based on
> request params, cookies etc? Since JSPs in Sling appear to be
> either precompiled with JSPC or compiled when requested as the the
> script corresponding to a resource type, would it work to just put a
> JSP script somewhere in the repo?
>
>
>
> Tobias Bocanegra wrote:
>> hi,
>>
>> On 7/28/08, Rory Douglas <ro...@oracle.com> wrote:
>>
>>> I have registered a couple of custom nodetypes with corresponding
>>> rendering
>>> scripts html.jsp in the appropriate folder. Now I'd like to
>>> include a few
>>> simple forms to create that node type (re-using as much existing
>>> functionality as possible). What is the best way to do this?
>>>
>>> I had a few ideas: (assume I have a nodetype test:Widget with a
>>> display
>>> script /apps/test/Widget/html.jsp)
>>>
>>> 1) Create "form" nodes (/forms/Widget/create)
>>> a) use sling:resourceType="form:Widget"
>>> b) register a script /apps/form/Widget/html.jsp that generates
>>> an HTML
>>> form (and uses the SlingPostServlet to create the content)
>>>
>>> 2) Create an "empty" Widget node (/content/Widget/new)
>>> a) use jcr:primaryResourceType="test:Widget"
>>> b) register a script with a "create" selector
>>> apps/test/Widget/create.html.jsp that generates the HTML
>>> form
>>>
>>
>> you can simply use a form that posts to the node you want to
>> create, eg:
>>
>> <form action="/content/newnode" method="POST">
>> <input type="hidden" name="jcr:primaryType" value="test:Widget"/>
>> <input type="text" name="title" value="" />
>> <form>
>>
>>
>>> I assume I could also register new servlets by paths, and then
>>> either
>>> directly create content or somehow forward to the
>>> SlingPostServlet. In all
>>> cases where I use the SlingPostServlet, what's the best way to
>>> handle
>>> failures or errors?
>>>
>> you can either post to a hidden frame, and the read the response via
>> the DOM or use an AJAX post and read the response.
>>
>> regards, toby
>>
>
> --
>
>
>
>
> Rory Douglas | Senior Principal Consultant
> Fax: +1-201-604-6428 | Mobile: +1-917-498-5344
> Oracle North America Consulting
> ORACLE United States | | San Diego, CA
> "Please consider your environmental responsibility before printing
> this e-mail"
>
--
Lars Trieloff
lars.trieloff@day.com / +49 173 6169716
http://wiki.day.com/content/wiki/Users/ltrielof.html
Re: Node creation form best practice
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Mon, Jul 28, 2008 at 11:11 PM, Rory Douglas <ro...@oracle.com> wrote:
> ...I guess it might be possible to make a fairly generic "form" JSP
> that reads a property (say, form:createResourceType") from the dummy node to
> figure out what node it's going to create and then looks up the NodeType &
> configures it's UI accordingly, I'll give it a try....
Sounds good, a script taking content values to adapt its behavior is
totally within Sling's way of doing things.
-Bertrand
Re: Node creation form best practice
Posted by Rory Douglas <ro...@oracle.com>.
Thanks all, that was what I needed. Setting the mimeType on the
jcr:content node worked for basic HTML.
The dummy node with sling:resourceType is what I was leaning towards
with my 1) option. I guess it might be possible to make a fairly
generic "form" JSP that reads a property (say, form:createResourceType")
from the dummy node to figure out what node it's going to create and
then looks up the NodeType & configures it's UI accordingly, I'll give
it a try.
Bertrand Delacretaz wrote:
> On Mon, Jul 28, 2008 at 10:16 PM, Rory Douglas <ro...@oracle.com> wrote:
>
>
>> ...curl -X PUT -d @createNewWidget.html
>> "http://admin:admin@localhost:8888/forms/widgets/createNewWidget.html"
>>
>> When I request that path (/forms/widgets/createNewWidget.html), my browser
>> tries to download me the source rather than display the HTML. I assume I
>> need to add some kind of contentType attribute when I upload the form, I'll
>> look into that....
>>
>
> You're right about the Content-Type, and the easiest way to get this
> right is to use a WebDAV client to upload your scripts and forms to
> the repository. The WebDAV root URL is http://localhost:8888/ for the
> launchpad webapp.
>
>
>> ..Also, how would I deploy a dynamic form (say, JSP-based), that might
>> configure it's display, default values etc differently based on request
>> params, cookies etc? Since JSPs in Sling appear to be either precompiled
>> with JSPC or compiled when requested as the the script corresponding to a
>> resource type, would it work to just put a JSP script somewhere in the repo?...
>>
>
> Yes, but to trigger the JSP you need a node that has the correct node
> type. For example, create a /bin/foo node with sling:resourceType=bar,
> and a script found at /apps/bar/bar.jsp will be executed when you
> request /bin/foo.html
>
> -Bertrand (just read Lars almost midair-colliding response, we're
> basically saying the same thing ;-)
>
--
Rory Douglas | Senior Principal Consultant
Fax: +1-201-604-6428 | Mobile: +1-917-498-5344
Oracle North America Consulting
ORACLE United States | | San Diego, CA
"Please consider your environmental responsibility before printing this
e-mail"
Re: Node creation form best practice
Posted by Bertrand Delacretaz <bd...@apache.org>.
On Mon, Jul 28, 2008 at 10:16 PM, Rory Douglas <ro...@oracle.com> wrote:
> ...curl -X PUT -d @createNewWidget.html
> "http://admin:admin@localhost:8888/forms/widgets/createNewWidget.html"
>
> When I request that path (/forms/widgets/createNewWidget.html), my browser
> tries to download me the source rather than display the HTML. I assume I
> need to add some kind of contentType attribute when I upload the form, I'll
> look into that....
You're right about the Content-Type, and the easiest way to get this
right is to use a WebDAV client to upload your scripts and forms to
the repository. The WebDAV root URL is http://localhost:8888/ for the
launchpad webapp.
> ..Also, how would I deploy a dynamic form (say, JSP-based), that might
> configure it's display, default values etc differently based on request
> params, cookies etc? Since JSPs in Sling appear to be either precompiled
> with JSPC or compiled when requested as the the script corresponding to a
> resource type, would it work to just put a JSP script somewhere in the repo?...
Yes, but to trigger the JSP you need a node that has the correct node
type. For example, create a /bin/foo node with sling:resourceType=bar,
and a script found at /apps/bar/bar.jsp will be executed when you
request /bin/foo.html
-Bertrand (just read Lars almost midair-colliding response, we're
basically saying the same thing ;-)
Re: Node creation form best practice
Posted by Rory Douglas <ro...@oracle.com>.
Thanks Toby
I guess my question is even simpler then - where do you store those
forms? I've tried uploading .HTML forms to the repository:
curl -X PUT -d @createNewWidget.html
"http://admin:admin@localhost:8888/forms/widgets/createNewWidget.html"
When I request that path (/forms/widgets/createNewWidget.html), my
browser tries to download me the source rather than display the HTML. I
assume I need to add some kind of contentType attribute when I upload
the form, I'll look into that.
Also, how would I deploy a dynamic form (say, JSP-based), that might
configure it's display, default values etc differently based on request
params, cookies etc? Since JSPs in Sling appear to be either
precompiled with JSPC or compiled when requested as the the script
corresponding to a resource type, would it work to just put a JSP script
somewhere in the repo?
Tobias Bocanegra wrote:
> hi,
>
> On 7/28/08, Rory Douglas <ro...@oracle.com> wrote:
>
>> I have registered a couple of custom nodetypes with corresponding rendering
>> scripts html.jsp in the appropriate folder. Now I'd like to include a few
>> simple forms to create that node type (re-using as much existing
>> functionality as possible). What is the best way to do this?
>>
>> I had a few ideas: (assume I have a nodetype test:Widget with a display
>> script /apps/test/Widget/html.jsp)
>>
>> 1) Create "form" nodes (/forms/Widget/create)
>> a) use sling:resourceType="form:Widget"
>> b) register a script /apps/form/Widget/html.jsp that generates an HTML
>> form (and uses the SlingPostServlet to create the content)
>>
>> 2) Create an "empty" Widget node (/content/Widget/new)
>> a) use jcr:primaryResourceType="test:Widget"
>> b) register a script with a "create" selector
>> apps/test/Widget/create.html.jsp that generates the HTML
>> form
>>
>
> you can simply use a form that posts to the node you want to create, eg:
>
> <form action="/content/newnode" method="POST">
> <input type="hidden" name="jcr:primaryType" value="test:Widget"/>
> <input type="text" name="title" value="" />
> <form>
>
>
>> I assume I could also register new servlets by paths, and then either
>> directly create content or somehow forward to the SlingPostServlet. In all
>> cases where I use the SlingPostServlet, what's the best way to handle
>> failures or errors?
>>
> you can either post to a hidden frame, and the read the response via
> the DOM or use an AJAX post and read the response.
>
> regards, toby
>
--
Rory Douglas | Senior Principal Consultant
Fax: +1-201-604-6428 | Mobile: +1-917-498-5344
Oracle North America Consulting
ORACLE United States | | San Diego, CA
"Please consider your environmental responsibility before printing this
e-mail"
Re: Node creation form best practice
Posted by Tobias Bocanegra <to...@day.com>.
hi,
On 7/28/08, Rory Douglas <ro...@oracle.com> wrote:
> I have registered a couple of custom nodetypes with corresponding rendering
> scripts html.jsp in the appropriate folder. Now I'd like to include a few
> simple forms to create that node type (re-using as much existing
> functionality as possible). What is the best way to do this?
>
> I had a few ideas: (assume I have a nodetype test:Widget with a display
> script /apps/test/Widget/html.jsp)
>
> 1) Create "form" nodes (/forms/Widget/create)
> a) use sling:resourceType="form:Widget"
> b) register a script /apps/form/Widget/html.jsp that generates an HTML
> form (and uses the SlingPostServlet to create the content)
>
> 2) Create an "empty" Widget node (/content/Widget/new)
> a) use jcr:primaryResourceType="test:Widget"
> b) register a script with a "create" selector
> apps/test/Widget/create.html.jsp that generates the HTML
> form
you can simply use a form that posts to the node you want to create, eg:
<form action="/content/newnode" method="POST">
<input type="hidden" name="jcr:primaryType" value="test:Widget"/>
<input type="text" name="title" value="" />
<form>
> I assume I could also register new servlets by paths, and then either
> directly create content or somehow forward to the SlingPostServlet. In all
> cases where I use the SlingPostServlet, what's the best way to handle
> failures or errors?
you can either post to a hidden frame, and the read the response via
the DOM or use an AJAX post and read the response.
regards, toby