Felix,

Thanks for the reply.  I'm still having a little trouble with this. If
for example I have a form whose inputs are populated by values in the
current node (as all the examples I have seen do).  This form is loaded
by a call to "/content/pathToEditScript" and is contained in edit.esp:

<form method="POST" action="/content/pathToPostValidationScript">
        <input type="text" name="title" value="<%= currentNode.title
%>"/>
        <input type="text" name="content" value="<%= currentNode.content
%>"/>
        <input type="submit" />
</form>

If my post validation script is as you outline:

    if (validate(request)) {
       String actualResourcePath = ....;
       RequestDispatcher rd = request.getRequestDispatcher(
                    actualResourcePath, "sling/servlet/default");
       rd.forward(request, response);
    } else {
       // draw the form with messages
    }

How do I reload the edit.esp form but have the values populated by the
posted values instead of the currentNode values.  Is the intent that in
the        "// draw the form with messages" section I would forward to
edit.esp and edit.esp would have logic to know if it should populate
from the currentNode or from the request.  

Perhaps I am just not getting how this whole thing works.  The
documentation is a bit sparse and I haven't found any example anywhere
that validates data.  Please forgive me if seem ridiculously stupid.

-----Original Message-----
From: Felix Meschberger [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 09, 2008 5:34 AM
To: [email protected]
Subject: Re: Data Validation

Hi Darrel,

Darrell Pittman schrieb:
> I am not sure if this is the place to post how-to questions but here
goes:  Can someone tell me if it is possible to validate posted data
(without relying on NodeTypes) and re-render the edit/add form with the
posted data (and validation errors) upon validation failure.

Considering you are using Sling and SlingPostServlet to update data, you
are certainly at the right place ;-)

Currently, the SlingPostServlet just updates the repository with your
posted data without any validation.

But you have a series of options to cope with this.

You can have your specialized servlet checking the data and redirecting
to the form again in case of validation faliure. In case of validation
success you forward the request to the SlingPostServlet by overwriting
the resource type and optionally use a different resource path to apply
the data to, for example:

    if (validate(request)) {
       String actualResourcePath = ....;
       RequestDispatcher rd = request.getRequestDispatcher(
                    actualResourcePath, "sling/servlet/default");
       rd.forward(request, response);
    } else {
       // draw the form with messages
    }



Alternatively you may install a request-level Filter which (on POST)
checks the input and passes the request on success or redirects the
requets to drawing the form again with messages in case of failure.

Hope this helps.

Regards
Felix

Reply via email to