Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Refresh handling in JSF

Tags:

jsf

jsf-2

Is there a way i can handle browser refreshes event inside my JSF 2.0 application so that the user be navigated to the welcome page when a browser refreshes the page? and that leads me to another question of how to make page navigation inside managed bean?

Cheers,

like image 665
seeed Avatar asked Nov 04 '22 23:11

seeed


1 Answers

Use a single view wherein you conditionally render includes.

<h:panelGroup id="body">
    <ui:include src="#{bean.page}.xhtml" />
</h:panelGroup>

Make the bean view scoped and use commandlinks with <f:ajax> to change the included page.

<h:form>
    <h:commandLink value="Page 1" action="#{bean.setPage('page1')}">
        <f:ajax execute="@this" render=":body" />
    </h:commandLink>
    <h:commandLink value="Page 2" action="#{bean.setPage('page2')}">
        <f:ajax execute="@this" render=":body" />
    </h:commandLink>
</h:form>

If you set the welcome page as default include page during bean's (post)construction, then a fresh new GET request will always show the welcome page. The only disadvantage is that those pages are not bookmarkable anymore, but that doesn't seem to be a major concern given this particular functional requirement.

like image 64
BalusC Avatar answered Nov 11 '22 23:11

BalusC