public class MyBean1 {
// Actions -----------------------------------------------------------------------------------
// Using RequestMap. NOTE: myBean2 should be request scoped and already created!
public void action1() {
MyBean2 myBean2 = (MyBean2) FacesContext.getCurrentInstance().getExternalContext()
.getRequestMap().get("myBean2");
// This only works if myBean2 is request scoped and already created.
if (myBean2 != null) {
myBean2.getText().setValue("action1");
}
}
// Using SessionMap. NOTE: myBean2 should be session scoped and already created!
public void action2() {
MyBean2 myBean2 = (MyBean2) FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().get("myBean2");
// This only works if myBean2 is session scoped and already created.
if (myBean2 != null) {
myBean2.getText().setValue("action2");
}
}
// Using ApplicationMap. NOTE: myBean2 should be application scoped and already created!
public void action3() {
MyBean2 myBean2 = (MyBean2) FacesContext.getCurrentInstance().getExternalContext()
.getApplicationMap().get("myBean2");
// This only works if myBean2 is application scoped and already created.
if (myBean2 != null) {
myBean2.getText().setValue("action3");
}
}
// Using VariableResolver. NOTE: this is deprecated since JSF 1.2!
public void action4() {
FacesContext context = FacesContext.getCurrentInstance();
MyBean2 myBean2 = (MyBean2) context.getApplication()
.getVariableResolver().resolveVariable(context, "myBean2");
myBean2.getText().setValue("action4");
}
// Using ValueBinding. NOTE: this is deprecated since JSF 1.2!
public void action5() {
FacesContext context = FacesContext.getCurrentInstance();
MyBean2 myBean2 = (MyBean2) context.getApplication()
.createValueBinding("#{myBean2}").getValue(context);
myBean2.getText().setValue("action5");
}
// Using ELResolver. NOTE: this is implemented since JSF 1.2!
public void action6() {
FacesContext context = FacesContext.getCurrentInstance();
MyBean2 myBean2 = (MyBean2) context.getELContext()
.getELResolver().getValue(context.getELContext(), null, "myBean2");
myBean2.getText().setValue("action6");
}
// Using ValueExpression. NOTE: this is implemented since JSF 1.2!
public void action7() {
FacesContext context = FacesContext.getCurrentInstance();
MyBean2 myBean2 = (MyBean2) context.getApplication().getExpressionFactory()
.createValueExpression(context.getELContext(), "#{myBean2}", MyBean2.class)
.getValue(context.getELContext());
myBean2.getText().setValue("action7");
}
// Using evaluateExpressionGet. NOTE: this is implemented since JSF 1.2!
public void action8() {
FacesContext context = FacesContext.getCurrentInstance();
MyBean2 myBean2 = (MyBean2) context.getApplication()
.evaluateExpressionGet(context, "#{myBean2}", MyBean2.class);
myBean2.getText().setValue("action8");
}
}