How to determine if the user was able to go to the page according to the JSF navigation rule or redirect the URL?

Is there any way in JSF that can be used to find out if the user reached the page based on the JSF navigation rule or the user typed the URL directly to access this page?

In fact, I want the user to not get to the page directly by typing the URL for this directly in the browser, instead I want to limit the use of the application’s navigation bar to go to the page.

+5
source share
1 answer

There is a way: check for a header referer(yes, with an error).

if (externalContext.getRequestHeader("referer") == null) {
    // User has most likely accessed the page by directly typing the URL.
}

or

<h:panelGroup rendered="#{empty header['referer']}">
    <!-- User has most likely accessed the page by directly typing the URL. -->
</h:panelGroup>

, -, , -//, referer.

, , , /WEB-INF , POST ( ajax). .

<h:form>
    <h:commandLink action="#{bean.showPage}" />
</h:form>

<h:panelGroup rendered="#{bean.showPage}">
    <ui:include src="/WEB-INF/includes/foo.xhtml" />
</h:panelGroup>
+5

All Articles