Session variables again
Hi,
I am very new to JSF and I am trying to find my feet by experimenting. I recently tried to define session variables which I could reference in my jsp's to do common things like display the title of a page.
My problem is cannot figure out how to change the value of such a session variable from the constructor of one the backing beans of a faces jsp.
In my faces config I have the following:
<managed-bean>
<managed-bean-name>pc_Globals</managed-bean-name>
<managed-bean-class>pagecode.Globals</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>title</property-name>
<value>WesBank Intranet: Home</value>
</managed-property>
<managed-property>
<property-name>leftHead</property-name>
<value>Home</value>
</managed-property>
</managed-bean>
And I want to change 'leftHead' to something else depending on the page being browsed.
Could anyone please give me a clue as to how to do this and also if you have any suggestions on what might be a better approach to achieve the same thing that will even be more appreciated.
Thanks alot
newbie
[1344 byte] By [
lordfeia] at [2007-10-2 16:55:39]

I don't actually use managed-property's for my managed-bean's, but you could probably set it up like this:
<managed-bean>
<managed-bean-name>pc_Globals</managed-bean-name>
<managed-bean-class>pagecode.Globals</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>title</property-name>
<value>#{pc_Globals.title}</value>
</managed-property>
<managed-property>
<property-name>leftHead</property-name>
<value>#{pc_Globals.leftHead}</value>
</managed-property>
</managed-bean>
And then in your pagecode.Globals class, you will add a getter and setter for each managed property-name. i.e. getTitle and setTitle. These methods will return a variable containing the String value for title. You can set the title in the constructor then.
Here's, IMHO, a better way to do it...
Remove the managed-property's from the managed-bean tag. Just keep the managed-bean-name, managed-bean-class, and managed-bean-scope.
Add the getters and setters to the pagecode.Globals class. Just like you would've above. So your pagecode.Globals class will have something that looks like this:
String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
You can set the title and any other properties to a default in your constructor.
Then, on your JSP, you can access the property like this:
<h:outputText value="#{pc_Globals.title}" />
Hope that helps,
CowKing