JSF server side validation on browser back button hit - validation

Is there any way to differentiate a browser back button request and a submit request in the listener?
Is there a way to do server side validation when a user hits browser back button & forward button consecutively?

Is there any way to differentiate a browser back button request and a submit request in the listener?
Not in the server side. The back button request is namely not necessarily been sent to the server, but instead requested on the browser's cache.
Is there a way to do server side validation when a user hits browser back button & forward button consecutively?
Just tell the browser to not cache the page at all. This way it will guarantee send a full request to the server side where all the associated code will be invoked.
You can find a kickoff example of such a filter in this answer: Avoid back button on JSF web application.

Related

What has been sent in POST?

I have a form on a web page. When I click the Submit button, the browser sends the form data within a POST request. If I refresh the result then it sends the data again.
I want to see what the POST data was without re-sending the form. How can I do it?
I know, there is the Developer Tools dialog which can show me what requests are being sent to the server. But, in order to analyze a request, I need to turn the DT on before I send the request. So, if I want to see what the POST content was, I need to send the form again, which I wanted to avoid.
I am sure that the browser knows what content of the POST was because if I refresh the result page, it will send the same POST data again. How can I access this information?
I would like to know the answer how to do it in Firefox but I am interested in Chrome as well.

Expire Page after page submit in MVC

Is there a way to expire a form after the user presses submit and redirected to another external url.
I want to restrain the user from clicking the browser's back button and resubmit the form.
I have tried to set NoCache and NoStore in the Controller but the browser still held in cache (Chrome).
This has nothing to do with MVC, the cache, or your browser; this is how HTTP headers handle POST requests.
Normally, when submitting a form to an internal or external URL you can avoid POST data being resubmitted by issuing a 302 "Moved Temporarily" redirect after you've processed the data, or by sending the request with AJAX or cURL.
There are multiple examples with answers on Stack Overflow, simply search for "prevent form resubmission"

Is it smart to load dynamic (text+media) content via websocket?

Say I have a web page, and it has a websocket chat running on it. Now, my plan is, when the user clicks on any of the links of the page, the page is not refreshed. Instead, I send the request to the websocket (the same one on which the chat is running), and it returns the new page.
So, is this a good idea? Or should I go for Ajax?
Ajax would be easier. You don't need branching inside the chat websocket listener this way, just request the needed page and put the response into the page body.

How to process request and do not return anything in spring

I am sending ajax request to spring controller from dialog box. The request is processed correctly, but after that dialog box is get closed and page is redirected to the url send in request.
I tried #RequestStatus(HttpStatus.OK) to not send any view name. Still page gets refreshed.
What I want is to remain dialog box open which sends request and page should not get refreshed.

difference between ajax and form submit

I just want to know what is the difference between sending parameter with ajax(post/get) to a servlet and sending them with "submit" .
Thanks for your help.
A standard form submit sends a new HTTP request (POST or GET) and loads the new page in the browser. In Ajax, the data is sent to the server (POST or GET) in the background, without affecting the page at all, and the response is then received by javascript in the background, again without affecting the page at all.
(The javascript can, of course, then use the data received from the server to update some of the page content.)
Ajax is generally useful where only a small section of the page content will change.
At the simplest, with ajax, you don't witness page refresh while submitting form data. And if you don't use it eg you use submit buttons, you witness page refresh. Both submit the data.
Server side handling of both are exactly the same. The server is not concerned about how the post request is made.
The difference is in how the browser (client side) responds to both the actions. The browser usually decides to make a request for an entire page if it is a form submit; otherwise, it just updates a part of the page.
From the servlet's point of view there is no difference. For the client, a submit will load a new page, while an Ajax request will parse the response with javascript code and act accordingly.
The form submit will reload the page that you are working on client side.,while in ajax call the call was made to server will not reload your client side page

Resources