|
子。UIViewRoot 是 Composite 类,而 UIOutput(比方说)就是叶子(或者基本类)。UIComponentBase 类定义了叶子和复合对象的公共方法,如编码/解码值和子节点管理函数。子节点管理函数,如 getChildren,对于叶子节点返回空列表,对于复合节点则返回其子节点。
Decorator 模式
Decorator 模式的目的是不通过子类化动态扩展对象的行为。JSF 框架有很多扩展点(即可插入机制)。JSF 实现可使用 Decorator 模式替换默认的 PropertyResolver、VariableResolver、ActionListener、NavigationHandler、ViewHandler 或 StateManager。通常自定义实现接受通过构造函数传递给它的默认实现的引用。自定义实现仅仅改写功能的一个子集,而将其他功能委托给默认实现。如果希望实现自定义的 ViewHandler,改写默认 ViewHandler 实现的 calculateLocale 方法,可以像 清单 1 那样编写 CustomViewHandler 类: 清单 1. CustomViewHandler 片段
public class CustomViewHandler extends ViewHandler {
public CustomViewHandler(ViewHandler handler) {
super();
oldViewHandler = handler;
}
private ViewHandler oldViewHandler = null;
public void renderView (facesContext context, UIViewRoot view) {
//delegate method to oldViewHandler
oldViewHandler.renderView(context, view);
}
//custom implementation of calculateLocale
public Locale calculateLocale(FacesContext context) {
}
}
Strategy 模式
Strategy 模式的目的是封装不同的概念。JSF 框架采用 Strategy 模式使用委托实现模型呈现 UI 组件。JSF 技术支持两种呈现模型。在直接实现模型中,UI 组件对收到的请求中的数据进行解码,然后编码这些数据进行显示。在委托实现模型中,解码和编码操作委托给和组 上一页 [1] [2] [3] [4] [5] [6] 下一页
|