I am currently working on a JSF application, and am trying to get two managed beans to communicate with each other. I am trying to achieve this using the Java "static" keyword, which allows me to access a class's variables without having to instantiate the class. For example:
public class Bean1
{
private static Integer myVariable;
public static Integer getMyVariable()
{
return myVariable;
}
public static void setMyVariable(Integer newVariable)
{
myVariable = newVariable;
}
}
public class Bean2
{
public String myMethod()
{
System.out.println("Bean1 myVariable: " +
Bean1.getMyVariable());
}
}
This works for me, as long as both Bean1 and Bean2 are initialized. Is there a safer, more JSF-friendly way to do something of this nature?