as title explains itself, have issue managing active tab in tab menu. i'm using jsf 2.1 w/ pf 3.4. here code fragment tab menu:
<h:form> <p:tabmenu activeindex="#{navigationmb.activeindex}" > <p:menuitem value="početna" action="#{navigationmb.navigatestudent('home')}" icon="ui-icon-home" /> <p:menuitem value="konsultacije" action="#{navigationmb.navigatestudent('konsultacije')}" icon="ui-icon-search" /> <p:menuitem value="zakazivanje" action="#{navigationmb.navigatestudent('zakazivanje')}" icon="ui-icon-document"/> <p:menuitem value="profesori" action="#{navigationmb.navigatestudent('profesori')}"/> <p:menuitem value="moj profil" action="#{navigationmb.navigatestudent('profil')}" icon="ui-icon-person" /> </p:tabmenu> </h:form>
here code of backing bean serves sole purpose of navigating tab menu:
@named(value = "navigationmb") @requestscoped public class navigationmb { private int activeindex = 0; public navigationmb() { } public string navigatestudent(string page) { system.out.println("go page " + page); if ("home".equals(page)) { activeindex = 0; return "/student/home?faces-redirect=true"; } if ("konsultacije".equals(page)) { activeindex = 1; return "/student/allconsults?faces-redirect=true"; } if ("zakazivanje".equals(page)) { activeindex = 2; return "/student/newconsult?faces-redirect=true"; } if ("profesori".equals(page)) { activeindex = 3; return "/student/allprofessors?faces-redirect=true"; } if ("profil".equals(page)) { activeindex = 4; return "/student/profile?faces-redirect=true"; } return ""; }
this runs fine when browsing, when logout (invalidate session) , later return same or different user, activeindex remembered. not understanding here? suppose request scoped bean created every time there's navigation action, , if user doesn't navigate anywhere, integer set 0 point "home" doesn't. awesome.
edit:
it seems without logging out, when 2 users (two tabs in browser) navigate around, if user 1 clicks on, instance, tab menu item 2, , user 2 refreshes page, user 2 see tab menu item 2 selected well, , vice versa.
edit2: made mistake previous edit, please forget above (i didn't notice refresh on user 2 side loads user 1 view).
as discussed among comments of question, bean not recognized being request scoped. created during application startup , lives long application running.
as spring used, using spring annotations resolve issue:
@scope("request") public class navigationmb { }
for request scoped bean, or:
@scope("session") public class navigationmb { }
to make session scoped.
Comments
Post a Comment