Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在页面之间存储共享数据以及如何控制数据的最佳实践_Java_Session_Oracle Adf - Fatal编程技术网

Java 在页面之间存储共享数据以及如何控制数据的最佳实践

Java 在页面之间存储共享数据以及如何控制数据的最佳实践,java,session,oracle-adf,Java,Session,Oracle Adf,我正在使用jdeveloper11.1.2.3中的ADF技术构建Fusion web应用程序。有时我们需要在页面之间存储共享变量,例如员工id、员工角色,有时Boolean变量用作标志属性 我的问题是这样做的最佳实践是什么?现在我正在使用会话范围存储这些数据,但我不确定这是否是首选方式 例如,如果我想在会话中存储某些内容,我将执行以下操作: FacesContext fc = FacesContext.getCurrentInstance(); ExternalC

我正在使用
jdeveloper11.1.2.3
中的
ADF
技术构建Fusion web应用程序。有时我们需要在页面之间存储共享变量,例如员工id、员工角色,有时
Boolean
变量用作标志属性

我的问题是这样做的最佳实践是什么?现在我正在使用
会话范围
存储这些数据,但我不确定这是否是首选方式

例如,如果我想在会话中存储某些内容,我将执行以下操作:

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ectx = fc.getExternalContext();
        HttpSession userSession = (HttpSession)ectx.getSession(true);
        userSession.setAttribute("userID", [user id attribute goes here]);
        Map sessionScope = ADFContext.getCurrent().getSessionScope();
        [data type] userIDFromSession = ([data type])sessionScope.get("userID");
如果我想取回它,我将执行以下操作:

        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext ectx = fc.getExternalContext();
        HttpSession userSession = (HttpSession)ectx.getSession(true);
        userSession.setAttribute("userID", [user id attribute goes here]);
        Map sessionScope = ADFContext.getCurrent().getSessionScope();
        [data type] userIDFromSession = ([data type])sessionScope.get("userID");

但是我不知道如何在执行过程中清除会话,我也不知道是否有更好的方法来做同样的事情。

如果这些是来自页面的值,为什么要从后台Java代码访问它们?为什么不使用表达语言? 如果页面位于同一任务流中,则应使用PageFlowScope。在表达式语言中创建一个bean、MyBean和access,如下所示: #{pageFlowScope.myBean.attribute} 提交页面时,会自动调用getAttribute。呈现页面时,会自动调用setAttribute。 要从支持Java代码访问bean,此实用程序类中有一些有用的方法