wicket学习之WebApplication 方法internalInit
程序员文章站
2022-07-15 15:14:15
...
在应用初始化,也就是WicketFilter初始化的时候,会调用WebApplication的internalInit()(先调用父类的internalInit(),完成初始化资源)完成系统资源的初始化
下面对WebApplication的internalInit()进行解析:
首先调用Application的internalInit()
1、初始化pageSettings
// Install default component resolvers(component resolvers:实现component的展示)
pageSettings.addComponentResolver(new ParentResolver());
pageSettings.addComponentResolver(new AutoComponentResolver());
pageSettings.addComponentResolver(new MarkupInheritanceResolver());
pageSettings.addComponentResolver(new HtmlHeaderResolver());
pageSettings.addComponentResolver(new WicketLinkResolver());
pageSettings.addComponentResolver(new WicketMessageResolver());
pageSettings.addComponentResolver(new WicketMessageTagHandler());
pageSettings.addComponentResolver(new FragmentResolver());
pageSettings.addComponentResolver(new RelativePathPrefixHandler());
pageSettings.addComponentResolver(new EnclosureResolver());
pageSettings.addComponentResolver(new WicketContainerResolver());
pageSettings.addComponentResolver(new BorderBodyResolver());
2、设置ButtonImageResourceFactory
// Install button image resource factory
getResourceSettings().addResourceFactory("buttonFactory",new DefaultButtonImageResourceFactory());
3、保存当前的WebApplication到Application的属性Map<String, Application> applicationKeyToApplication
String通常为Filter的name
String applicationKey = getApplicationKey();
applicationKeyToApplication.put(applicationKey, this);
4、创建sessionStore(The actual store that is used by org.apache.wicket.Session to store its attributes.)
sessionStore = newSessionStore();
5、创建converterLocator(Implementation of {@link IConverterLocator} interface, which locates converters for a given type.)
converterLocator = newConverterLocator();
例如:set(Boolean.TYPE, BooleanConverter.INSTANCE);
至此Application的internalInit()结束
WebApplication的internalInit()的其他部分:
1、设置出错页面
// Set default error pages for HTML markup
getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class);
getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
2、// Add resolver for automatically resolving HTML links
getPageSettings().addComponentResolver(new AutoLinkResolver());
3、// Set resource finder to web app path
getResourceSettings().setResourceFinder(getResourceFinder());
4、提供客户化的配置,提供另外的路径,寻找文件,(不支持自动匹配子目录)
// Add optional sourceFolder for resources.
String resourceFolder = getInitParameter("sourceFolder");
if (resourceFolder != null)
{
getResourceSettings().addResourceFolder(resourceFolder);
}
5、// Configure the app.
主要针对开发环境和部署环境进行app的设置,下面的设置可以在WebApplication的init方法中作相应的改动
下面是针对开发环境的一段部署代码:
getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
getDebugSettings().setComponentUseCheck(true);
getMarkupSettings().setStripWicketTags(false);
getExceptionSettings().setUnexpectedExceptionDisplay(
IExceptionSettings.SHOW_EXCEPTION_PAGE);
getDebugSettings().setAjaxDebugModeEnabled(true);
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
// getDebugSettings().setOutputMarkupContainerClassName(true);
getResourceSettings().setJavascriptCompressor(null);
getRequestCycleSettings().addResponseFilter(EmptySrcAttributeCheckFilter.INSTANCE);
下面对WebApplication的internalInit()进行解析:
首先调用Application的internalInit()
1、初始化pageSettings
// Install default component resolvers(component resolvers:实现component的展示)
pageSettings.addComponentResolver(new ParentResolver());
pageSettings.addComponentResolver(new AutoComponentResolver());
pageSettings.addComponentResolver(new MarkupInheritanceResolver());
pageSettings.addComponentResolver(new HtmlHeaderResolver());
pageSettings.addComponentResolver(new WicketLinkResolver());
pageSettings.addComponentResolver(new WicketMessageResolver());
pageSettings.addComponentResolver(new WicketMessageTagHandler());
pageSettings.addComponentResolver(new FragmentResolver());
pageSettings.addComponentResolver(new RelativePathPrefixHandler());
pageSettings.addComponentResolver(new EnclosureResolver());
pageSettings.addComponentResolver(new WicketContainerResolver());
pageSettings.addComponentResolver(new BorderBodyResolver());
2、设置ButtonImageResourceFactory
// Install button image resource factory
getResourceSettings().addResourceFactory("buttonFactory",new DefaultButtonImageResourceFactory());
3、保存当前的WebApplication到Application的属性Map<String, Application> applicationKeyToApplication
String通常为Filter的name
String applicationKey = getApplicationKey();
applicationKeyToApplication.put(applicationKey, this);
4、创建sessionStore(The actual store that is used by org.apache.wicket.Session to store its attributes.)
sessionStore = newSessionStore();
5、创建converterLocator(Implementation of {@link IConverterLocator} interface, which locates converters for a given type.)
converterLocator = newConverterLocator();
例如:set(Boolean.TYPE, BooleanConverter.INSTANCE);
至此Application的internalInit()结束
WebApplication的internalInit()的其他部分:
1、设置出错页面
// Set default error pages for HTML markup
getApplicationSettings().setPageExpiredErrorPage(PageExpiredErrorPage.class);
getApplicationSettings().setInternalErrorPage(InternalErrorPage.class);
getApplicationSettings().setAccessDeniedPage(AccessDeniedPage.class);
2、// Add resolver for automatically resolving HTML links
getPageSettings().addComponentResolver(new AutoLinkResolver());
3、// Set resource finder to web app path
getResourceSettings().setResourceFinder(getResourceFinder());
4、提供客户化的配置,提供另外的路径,寻找文件,(不支持自动匹配子目录)
// Add optional sourceFolder for resources.
String resourceFolder = getInitParameter("sourceFolder");
if (resourceFolder != null)
{
getResourceSettings().addResourceFolder(resourceFolder);
}
5、// Configure the app.
主要针对开发环境和部署环境进行app的设置,下面的设置可以在WebApplication的init方法中作相应的改动
下面是针对开发环境的一段部署代码:
getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND);
getDebugSettings().setComponentUseCheck(true);
getMarkupSettings().setStripWicketTags(false);
getExceptionSettings().setUnexpectedExceptionDisplay(
IExceptionSettings.SHOW_EXCEPTION_PAGE);
getDebugSettings().setAjaxDebugModeEnabled(true);
getDebugSettings().setDevelopmentUtilitiesEnabled(true);
// getDebugSettings().setOutputMarkupContainerClassName(true);
getResourceSettings().setJavascriptCompressor(null);
getRequestCycleSettings().addResponseFilter(EmptySrcAttributeCheckFilter.INSTANCE);