我想从另一个类调用存储在 applicationScope 中的 ArrayList
我有一个类,像这样将一堆数据存储在公共变量名称 AL_data 中,getAllData 方法只是将数据存储在 AL_data
public class Application implements Serializable{
private static final long serialVersionUID = 1L;
public ArrayList<District> AL_data;
public Application(){
try {
getAllData();
} catch (NotesException e) {
e.printStackTrace();
}
}
}
我已经使用 applicationScope 将类设置为 faces-config 中的托管 bean
<managed-bean>
<managed-bean-name>App</managed-bean-name>
<managed-bean-class>com.utils.Application</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
我还有另一个类,我想用它来阅读应用程序范围
public class actions {
private static Map<String, Object> applicationScope() {
FacesContext context = FacesContext.getCurrentInstance();
return (Map<String, Object>) context.getApplication().getVariableResolver().resolveVariable(context,"applicationScope");
}
public Vector<String> getDataForCurrentUser() {
try {
// how do I access the AL_data arraylist stored in applicationscope
// ArrayList m = (ArrayList) this.applicationScope();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
我已使用 sessionScope 将此类设置为管理 bean。
<managed-bean>
<managed-bean-name>Actions</managed-bean-name>
<managed-bean-class>com.utils.actions</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
我想知道如何调用应用程序范围类并访问它的公共属性,或者如何返回我的 ArrayList。
谢谢
托马斯