java - navigate between pages with JSF -
i want navigate between pages inside tab code :
<p:tabview id="tabview"> <p:tab id="tab1" title="gestion des utilisateur" titlestyle="titre"> <ui:include src="#{directionpage.page}" /> </p:tab> <p:tab id="tab2" title="gestion des equipes"> <ui:include src="#{directionpage.page2}" /> </p:tab> </p:tabview> the directionpage jsf managed bean have variable string static page; , want change value of page in other managed beans navigate other page. having error : class 'com.jsfmanagedbean.directionpage' not have readable property 'page'.
and jsf managed bean
package com.jsfmanagedbean; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; @sessionscoped @managedbean public class directionpage { public static string page="/admin/gestiondesuser/usergestion.xhtml"; public static string page2="/admin/gestiondesequipe/gestiondesequipe.xhtml"; public static string getpage() { return page; } public static void setpage(string page) { directionpage.page = page; } public static string getpage2() { return page2; } public static void setpage2(string page2) { directionpage.page2 = page2; } public directionpage() { } } i tryed change value of page in other managed bean :
directionpage.page="/admin/gestiondesuser/createuser.xhtml"; so how can change static value of managedbean other managedbean ??
your code have serious problems:
don't use static variables hold user-specific data. because when more 1 user uses application, sharing same static variable static variables class-scoped , not instance-scoped. right code not thread-safe.
when try access managedbean xhtml code, refer class instance , not class itself. jsf follows javabean conventions , uses getters/setters of instance variable access instance variables. because 'page' variable , getter/setter methods class-scoped (static), jsf can not access mentioned variable. read javabean conventions , again, dont use static variables.
try follow java naming conventions ojota84 mentioned. here blog this: http://blog.sanaulla.info/2008/06/25/camelcase-notation-naming-convention-for-programming-languages/
it has side-effects if managed beans don't implement serializable interface. try make beans serializable.
navigating other pages changing variable in managed bean not perfect way handle navigation in jsf. see you're using primefaces suggest read jsf documentation , primefaces documentation first. don't know trying achieve can't more right issue.
for current problem, instead use approach (i didnt test code):
@sessionscoped @managedbean public class directionpage implements serializable { private string page="/admin/gestiondesuser/usergestion.xhtml"; private string page2="/admin/gestiondesequipe/gestiondesequipe.xhtml"; public string getpage() { return page; } public void setpage(string page) { this.page = page; } public string getpage2() { return page2; } public void setpage2(string page2) { this.page2 = page2; } public directionpage() { } } and can change values bean like
@sessionscoped @managedbean public class anotherbean implements serializable { @managedproperty("#{directionpage}") private directionpage directionpage; public void setdirectionpage(directionpage directionpage) { this.directionpage = directionpage; } public directionpage getdirectionpage() { return directionpage; } public void changepage() { directionpage.setpage("whateverpage"); } } hope helps.
Comments
Post a Comment