法1:首先获得ExternalContext 对象,然后取得参数Map,在Map中进行寻找。
Map params
=
FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
MyBean mybean = (MyBean ) params.get( " myBean " );
if (mybean != null )
... {
//do sth
}
MyBean mybean = (MyBean ) params.get( " myBean " );
if (mybean != null )
... {
//do sth
}
法2:利用CreateValueBinding方法进行查找,这样的好处是如果内存中该BEAN没有创建,JSF将自动创建一个实例,当然该BEAN应该在faces-config.xml中事先配置过。
FacesContext facesContext
=
FacesContext.getCurrentInstance();
Application app = facesContext.getApplication();
MyObject myObject = (MyObject)app.createValueBinding( " #{myObject} " ).
getValue(facesContext);
Application app = facesContext.getApplication();
MyObject myObject = (MyObject)app.createValueBinding( " #{myObject} " ).
getValue(facesContext);