Hi Freddy,

the response header seems to be the most suitable option. Setting it should
be as easy as

        return new ForwardResolution("/path/to/your/page.jsp") {
            @Override
            public void execute(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
                response.addHeader("success", "true");

                super.execute(request, response);
            }
        };

I tested this with Jetty 6.1.7 and Firebug show the response header. I've
never used jQuery, so I can't tell you how to read it.

Another option is to completely replace the divs (use outerHTML instead of
innerHTML) and check the ID. Again, I can't tell you how easy that would be
using jQuery.

Kind regards,
  Levi

On Tue, Jul 8, 2008 at 10:06 PM, Freddy Daoud <[EMAIL PROTECTED]> wrote:

> Stripers,
>
> I've run into a problem for which I found a simple but somewhat ugly
> solution. I'm trying to find a more elegant solution that doesn't
> increase complexity tenfold.
>
> Consider a page with a list of people in a div id="people" and a form,
> in the same page, in a div id="form". The form gets submitted via
> AJAX. If no validation errors occur, the response is the fragment that
> contains the refreshed list of people and should replace the "people" div.
> Validation errors return the form, much like the standard Stripes
> source page resolution except that it's just the form, not the entire
> page. In that case, the response fragment should replace the "form"
> div.
>
> The problem consists of receiving the page fragment and deciding where
> it should go: "people" or "form"? In other words, how would you
> signal, in the response, a success/validatione error flag along with
> the page fragment?
>
> To be clear and save everyone time, allow me to enumerate some
> solutions that do not satisfy my requirements:
>
> - returning an HTTP error code. When validation errors occur, the HTTP
>  status is still successful and the page fragment is valid; it
>  contains the form with the validation errors.
>
> - using JavaScriptResolution, JSON, XML data, etc. I do not want to
>  send raw data and have to rebuild the list of people or the form with
>  validation errors using JavaScript. That makes me feel like I'm back
>  in 1998, writing HTML code in Java Servlets. I want to send the page
>  fragments in the response, clean and simple.
>
> - setting an HTTP response header. I tried this and correct me if I'm
>  wrong, but setting a response header and then returning a
>  ForwardResolution does not work. I've also had some difficulty
>  retrieving the response header in the AJAX callback function (with
>  jQuery). I should mention that I'm open to this solution but I haven't
>  found how to resolve these issues.
>
> Right now I have an HTML comment in the list of people fragment. When
> receiving the response data, finding that comment in the data means
> success, and so put the fragment in "people". Otherwise, put the fragment
> in "form". Like I said: simple, but ugly.
>
> I also tried returning a JavaScriptResolution(url) upon success and
> the form with validation errors upon failure. If eval(response) works,
> I use the URL to refresh the list of people. This is similar to a
> redirect. Not bad, but I have to do a try/catch on the call to eval()
> because the HTML fragment with the form is obviously not valid
> JavaScript. So I find this solution almost as brittle as the previous
> one. If I return a JavaScriptResolution(true, url) on success and
> JavaScriptResolution(false, url) upon failure, I'd have to submit the
> form a second time, with some kind of indicator, to get the Stripes-
> generated form with validation errors. Somewhat a steep price to pay
> for elegance...
>
> Ideally, I would love to be able to just return a JavaScriptResolution
> (or JSON, whatever) with a simple Map:
> {"success": true, "data": "(html fragment)"}
> Then I could just check the flag to decide which div id to update with
> the data. The HTML page fragment, however, would have to be generated
> normally. That's the problem. I tried to executing a
> ForwardResolution with an HttpServletResponseWrapper to capture the
> output in a String, and put that in the JavaScriptResolution.
> Surprisingly complicated, and it doesn't even work. Jetty complains of
> an "already committed response" (even if I override isCommitted() to
> return false) and Tomcat throws an InvalidStateException. Even if I
> somehow got that to work, it feels like a hack-hack-ack-ack.
>
> If you're still with me, it all boils down to: how to elegantly attach
> some sort of additional data (in my case, a boolean flag) to a regular
> Stripes Resolution?
>
> Thanks in advance for any ideas on this.
>
> Cheers,
> Freddy
>
>
>
> -------------------------------------------------------------------------
> Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
> Studies have shown that voting for your favorite open source project,
> along with a healthy diet, reduces your potential for chronic lameness
> and boredom. Vote Now at http://www.sourceforge.net/community/cca08
> _______________________________________________
> Stripes-users mailing list
> Stripes-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to