在Ajax交互时,为了开发或使用上的便利性,专门提供了ViewContext对象。你可以将该对象视为Map结构的一个对象。该对象在Dorado的AJAX交互过程中会自动的同步客户端和服务器端的信息,凡是存储在ViewContext中的信息,无论在客户端JS编程还是在服务器端Java编码的时候都可以随时随地的存取其中的数据。
客户端存取范例代码:
view.set("context.attr1","testvalue"); var attr1 = view.get("context.attr1");
Java端存取范例代码:
DoradoContext context = DoradoContext.getCurrent(); context.setAttribute(DoradoContext.VIEW, "attr1", "testValue"); String attr1 = (String) context.getAttribute(DoradoContext.VIEW, "attr1");