WEB开发网
开发学院软件开发Java 借助 Ajax 自动保存 JSF 表单: 第 3 部分:保存 J... 阅读

借助 Ajax 自动保存 JSF 表单: 第 3 部分:保存 JSF 表单中的用户输入

 2009-11-10 00:00:00 来源:WEB开发网   
核心提示: 第 2 部分 还演示了 AutoSaveListener 类的 saveCurrentView() 方法,它用于处理表单自动保存请求,借助 Ajax 自动保存 JSF 表单: 第 3 部分:保存 JSF 表单中的用户输入(3),本节将讨论示例应用程序的 ViewRestorer 类,该类提供了一

第 2 部分 还演示了 AutoSaveListener 类的 saveCurrentView() 方法,它用于处理表单自动保存请求。本节将讨论示例应用程序的 ViewRestorer 类,该类提供了一个 restoreCurrentView() 方法和两个 JSF 事件侦听器,可处理恢复当前 JSF 视图数据的请求,简称为恢复请求。

清单 2 展示了 restoreCurrentView() 方法,它通过包装器 bean 访问存储库,以获取当前用户/视图组合的数据地图。然后,它将调用 restoreValues() 方法恢复输入组件的值。之后,restoreCurrentView() 调用 faces 上下文的 renderResponse() 方法,通知 JSF 框架实现 Render Response 阶段。在后文中您将看到,renderResponse() 调用将与 immediate 属性结合使用。


清单 2. 恢复当前 JSF 视图的数据
package autosave; 
 
import java.util.Map; 
... 
import javax.faces.component.UIViewRoot; 
import javax.faces.context.FacesContext; 
 
public class ViewRestorer implements java.io.Serializable { 
 
  public void restoreCurrentView() { 
    // Get the faces context of the current request. 
    FacesContext ctx = FacesContext.getCurrentInstance(); 
    // Get the root component of the current view. 
    UIViewRoot root = ctx.getViewRoot(); 
    // Get the managed bean instance wrapping the data repository. 
    RepositoryWrapper wrapper = RepositoryWrapper.getManagedBean(ctx); 
    // Get the data map for the current context. 
    Map<String, Object> dataMap = wrapper.getDataMap(ctx); 
    // Use the data map to restore the values of the JSF components. 
    DataMapRepository.restoreValues(root, dataMap); 
    // Signal the JSF framework to go to the Render Response phase. 
    ctx.renderResponse(); 
  } 
  ... 
} 

上一页  1 2 3 4 5 6 7 8  下一页

Tags:借助 Ajax 自动

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接