Redirect JSF page

Asked

Viewed 499 times

1

I have a Sessionscoped bean that I use to navigate data from page 1 to page 2. Page 1 is accessed through the menu, while page 2 is accessed by a button inside page 1, where some data based on filters are loaded from this first page. My question is the following: If the user type the url of this page 2 in hand, how can I redirect it to the first page?

  • 1

    What Voce wants is to prohibit access to certain users' Urls? For example, user x is not allowed to access page y. If he tries to access page y in hand he is redirected to login page?

  • Not certain users, but all. In case the user tries to enter page 2 manually, redirect to page 1. Until because if it goes straight to page 2 will give a blow, as it has data that are taken from page 1.

  • I thought of something now but I do not know if it works, Voce can create a phaseListener that checks if the data is null, if they are null the page can not be accessed

1 answer

0

Call a method from your Bean before initializing page 2, make sure the user has filled in the required data on page 1, if not redirect page 1.

Using the tags below, page 2 is not reloaded:

<f:metadata>
    <f:viewAction action="#{pagina2Bean.inicializar()}"/>
</f:metadata>

Obs.: tag (f) is from the JSF Core library.

Or do it with Javascript:

window.onload = new function(){
  #{pagina2Bean.inicilizar()}
}
  • I’m in favor of JS for basic functions like this, but the question was in JSF!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.