Cannot clear validation errors when form onSuccess returns a StreamResponse

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Cannot clear validation errors when form onSuccess returns a StreamResponse

Svein
If I record an error for my <t:palette> I cannot find out how to clear errors (tried form.clearErrors()).

Because onSuccess returns a StreamResponse to download a file the form need to have async="false"

The form should stay open so user can download several files with different parameters.

Can anyone help!

S-E
Reply | Threaded
Open this post in threaded view
|

Re: Cannot clear validation errors when form onSuccess returns a StreamResponse

Thiago H de Paula Figueiredo
Hi!

This is due to HTTP, not Tapestry itself: you cannot have two different
responses to the same request. So, you either rerender the page to clear
the errors (which calling form.clearErrors() is actually doing, even if you
cannot see the results) or returns a binary download (StreamResponse), but
not both.

You'll need to write some JavaScript for that, so either the form
submission or the file download request is done through JavaScript. Maybe
the easiest solution, even if not pretty, is to return null in onSuccess(),
rendering a <script> tag with a window.location = [URL which triggers the
download] statement.

On Mon, Sep 4, 2017 at 4:41 AM, Svein-Erik Løken <[hidden email]> wrote:

> If I record an error for my <t:palette> I cannot find out how to clear
> errors (tried form.clearErrors()).
>
> Because onSuccess returns a StreamResponse to download a file the form
> need to have async="false"
>
> The form should stay open so user can download several files with
> different parameters.
>
> Can anyone help!
>
> S-E
>



--
Thiago
Reply | Threaded
Open this post in threaded view
|

RE: Cannot clear validation errors when form onSuccess returns a StreamResponse

Svein
Thanks!

I was able to make this work. Do you think my solution is too complex Thiago?


/external/TrackSegmentsExport (the form):
==========================================

@Persist(PersistenceConstants.FLASH)
boolean download;

@AfterRender
void afterRender() {
    if (download) {
        javaScriptSupport.require("util/util").invoke("windowLocation").with("/external/TrackSegmentsExportDownload");
    }
}

Object onSuccessFromTrackExpForm() throws ParserConfigurationException, JAXBException, TransformerException, IOException {
    download = true;
    return null;
}



Utils.js:
==========================================
Util.windowLocation = function (href) {
    window.location = href;
};



/external/TrackSegmentsExportDownload:
==========================================

StreamResponse onActivate() {
...
return new AttachmentStreamResponse(stream, "TrackSegmentsExport.gpx");






From: Thiago H de Paula Figueiredo [via Apache Tapestry Mailing List Archives] [mailto:[hidden email]]
Sent: mandag 4. september 2017 13:48
To: Svein-Erik Løken <[hidden email]>
Subject: Re: Cannot clear validation errors when form onSuccess returns a StreamResponse

Hi!

This is due to HTTP, not Tapestry itself: you cannot have two different
responses to the same request. So, you either rerender the page to clear
the errors (which calling form.clearErrors() is actually doing, even if you
cannot see the results) or returns a binary download (StreamResponse), but
not both.

You'll need to write some JavaScript for that, so either the form
submission or the file download request is done through JavaScript. Maybe
the easiest solution, even if not pretty, is to return null in onSuccess(),
rendering a <script> tag with a window.location = [URL which triggers the
download] statement.

On Mon, Sep 4, 2017 at 4:41 AM, Svein-Erik Løken </user/SendEmail.jtp?type=node&node=5733608&i=0> wrote:

> If I record an error for my <t:palette> I cannot find out how to clear
> errors (tried form.clearErrors()).
>
> Because onSuccess returns a StreamResponse to download a file the form
> need to have async="false"
>
> The form should stay open so user can download several files with
> different parameters.
>
> Can anyone help!
>
> S-E
>



--
Thiago

________________________________________
If you reply to this email, your message will be added to the discussion below:
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Cannot-clear-validation-errors-when-form-onSuccess-returns-a-StreamResponse-tp5733607p5733608.html 
To unsubscribe from mailto:[hidden email] Mailing List Archives,
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml 

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Cannot clear validation errors when form onSuccess returns a StreamResponse

Thiago H de Paula Figueiredo
It looks better than mine, actually, since you're using JavaScriptSupport.
:)

On Mon, Sep 4, 2017 at 10:10 AM, Svein-Erik Løken <[hidden email]> wrote:

> Thanks!
>
> I was able to make this work. Do you think my solution is too complex
> Thiago?
>
>
> /external/TrackSegmentsExport (the form):
> ==========================================
>
> @Persist(PersistenceConstants.FLASH)
> boolean download;
>
> @AfterRender
> void afterRender() {
>     if (download) {
>         javaScriptSupport.require("util/util").invoke("
> windowLocation").with("/external/TrackSegmentsExportDownload");
>     }
> }
>
> Object onSuccessFromTrackExpForm() throws ParserConfigurationException,
> JAXBException, TransformerException, IOException {
>     download = true;
>     return null;
> }
>
>
>
> Utils.js:
> ==========================================
> Util.windowLocation = function (href) {
>     window.location = href;
> };
>
>
>
> /external/TrackSegmentsExportDownload:
> ==========================================
>
> StreamResponse onActivate() {
> ...
> return new AttachmentStreamResponse(stream, "TrackSegmentsExport.gpx");
>
>
>
>
>
>
> From: Thiago H de Paula Figueiredo [via Apache Tapestry Mailing List
> Archives] [mailto:[hidden email]]
> Sent: mandag 4. september 2017 13:48
> To: Svein-Erik Løken <[hidden email]>
> Subject: Re: Cannot clear validation errors when form onSuccess returns a
> StreamResponse
>
> Hi!
>
> This is due to HTTP, not Tapestry itself: you cannot have two different
> responses to the same request. So, you either rerender the page to clear
> the errors (which calling form.clearErrors() is actually doing, even if you
> cannot see the results) or returns a binary download (StreamResponse), but
> not both.
>
> You'll need to write some JavaScript for that, so either the form
> submission or the file download request is done through JavaScript. Maybe
> the easiest solution, even if not pretty, is to return null in onSuccess(),
> rendering a <script> tag with a window.location = [URL which triggers the
> download] statement.
>
> On Mon, Sep 4, 2017 at 4:41 AM, Svein-Erik Løken </user/SendEmail.jtp?type=node&node=5733608&i=0>
> wrote:
>
> > If I record an error for my <t:palette> I cannot find out how to clear
> > errors (tried form.clearErrors()).
> >
> > Because onSuccess returns a StreamResponse to download a file the form
> > need to have async="false"
> >
> > The form should stay open so user can download several files with
> > different parameters.
> >
> > Can anyone help!
> >
> > S-E
> >
>
>
>
> --
> Thiago
>
> ________________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-tapestry-mailing-list-archives.1045711.
> n5.nabble.com/Cannot-clear-validation-errors-when-form-
> onSuccess-returns-a-StreamResponse-tp5733607p5733608.html
> To unsubscribe from mailto:[hidden email] Mailing List
> Archives, http://apache-tapestry-mailing-list-archives.1045711.
> n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=
> 2375125&code=c3ZlaW5AamFjaWxsYS5ub3wyMzc1MTI1fC0xNTM4NzY2ODg4.
> http://apache-tapestry-mailing-list-archives.1045711.
> n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%
> 21nabble%3Aemail.naml&base=nabble.naml.namespaces.
> BasicNamespace-nabble.view.web.template.NabbleNamespace-
> nabble.view.web.template.NodeNamespace&breadcrumbs=
> notify_subscribers%21nabble%3Aemail.naml-instant_emails%
> 21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
>



--
Thiago
Reply | Threaded
Open this post in threaded view
|

RE: Cannot clear validation errors when form onSuccess returns a StreamResponse

Svein
Just curious: How can you return javascript code? / Without javaScriptSupport?


Reply | Threaded
Open this post in threaded view
|

Re: Cannot clear validation errors when form onSuccess returns a StreamResponse

Thiago H de Paula Figueiredo
You could just have something like <t:if
test="addJavascript">window.location = ...<script></script></t:if>. Pretty
hacky, even working.

On Mon, Sep 4, 2017 at 10:37 AM, Svein-Erik Løken <[hidden email]> wrote:

> Just curious: How can you return javascript code? / Without
> javaScriptSupport?
>
>
>


--
Thiago