How to implement back previous jsf page by clicking on back button on browser - jsf

Now I encounter one issue related with browser's back button. I hope it can forward to previous page with history when user click on browser's back button. But it always forward to index.xhtml from main.xhtml. I have some operation or page embedded in main.xhtml. Does someone have some idea about that? Or you find the issue of that. Thanks.

Related

Browser back button is not working in Blazor web-server

I want to go previous page when the user clicks on the browser back button. When I navigate another page, I can not go to the last page by using the browser back button. So, can anyone help me find a solution to this problem?
Ensure that every state that you want to show up in next/back is differentiated by a route change navigated to by NavigationManager.
If you make a page /somePage and you let the user step through several choices, and then the user navigates (using the URL bar) then hits the back button on the browser, they will go back to /somePage and not back to the choices they made.
If you make a page /somePage and each time the user makes a choice they are navigated to a new page using NavigationManager, for example /somePage/someSelection, then when they hit back they will go back to /somePage/someSelection. This requires you to load data on subpage choices on init based on optional page route parameters, but the tradeoff is having browser navigations that are part of next/back.

Prevent direct access to some page in JSF

I want to restrict direct access to certain page in my application. Those pages can only be accessible if the user is redirected to those pages by the application.
All the redirections are done via ExternalContext#redirect(url) method.
User can use back and forward button, also can refresh the page by pressing F5 or via browser's refresh button. What I want is user cannot save, or bookmark URLs of some page, also cannot copy those redistricted URL and paste and go via address bar of the browser.
Followings are the cases:
Say, I have Page-A and Page-B.
Redirection is done to Page-B from Page-A.
User can go back to Page-A and can come again to Page-B by using browser's back and forward button.
User can refresh Page-B and he/she will stay in Page-B.
User CANNOT copy the URL of Page-B and access it later time (in new tab or by bookmarking).
Is it feasible? Any pointer would be very helpful to me.
I don't think you can do all that from JSF.
Your obvious alternative is to use Javascript.
I never herd a concept of disabling Bookmark option in Browser using Javascript. However you can always disable the address field if you open the page in new Window.
You can solve it with
JSF Navigation Handler - set a session attribute from some previous page and expire the value after some time with a timer. From the Handler impl check the value of the attribute and restrict access e.g. redirect to some other page in case the value is not present.
You can achieve similar behaviour with web frameworks. Enforcing controlled navigation is a basic feature in most WEB FXs e.g. JBoss Seam conversations or Spring Web Flow controlled navigation implementations.

Browser back button navigation

Whenever browser back is clicked, it must not navigate to the previous page but to some default page. how is it done using JSF ?
Clicking on browser back button requests the result page from the browser cache.
This is a client side activity. It doesn't send request to your server for fetching some default page(in your case).
Please refer this post for writing a filter indicating the browser not to cache dynamic JSF pages.
And also you can refer this one for more details.
You can try to detect if User has clicked on browser back button by writing client side code.
Refer this post for detecting back button click.
If you are trying to alter the behaviour of browser back button, it indicates some kind of flaw in your application.

Reset View of webpage JSF

Is there a way to reset the view of a page in JSF?
I have a page to upload files and it keeps filling a table with the files the user wants to submit, once the user clicks on submit I want the page to be in the initial state as if it was the first time the user visited it.
Hope I explain myself correctly.
Well after searching and thinking a bit, I think I got it.
Just in the action attribute of the submit button redirect the page to the same page, this will cause to create a new view of the same page.

Browser navigation, back button issue

I want to know how you guys deal with back button issues in your web applications.
I can not forbid users to click back button on their browser, but when they hit it, the page code doesn't run. So writing in page_load() makes no sense.
I have searched online and found this link: Disabling Back button on the browser. It does not work for me. Any idea?
There is no way to disable the back button. You can try to open your page/form in a new window so there would be nothing to navigate back to
Normally, If I have a critical or lengthy form, I tend to maintain a dirty-flag and if the user starts entering something, the dirty-flag gets set and on save or submit it gets reset. You can use unload/beforeunload javascript event to see if the dirty-flag is set and ask for confirmation.

Resources