(1)概述
1.pull service作用
实际上pull service就相当于提供工具类,可以将工具定义成Java类,而能够在vm模板中调用
2.webx定义的pull service
[html] view plain copy
- <services:pull>
- <!-- Webx3 tools。 -->
- <pull-factories:utils />
- <pull-factories:rundata-tool />
- <pull-factories:csrfToken />
- <pull-factories:form-tool />
- <pull-factories:control-tool />
- <pull-factories:uris-tool />
- </services:pull>
(2)自定义PullService
1.定义工具类
[java] view plain copy
- public class DomTool {
- public void addScript(String scriptURI) {
- }
- public void addCss(String cssURI) {
- }
- }
2.实现ToolFactory接口
[java] view plain copy
- public class MyToolFactory implements ToolFactory {
- private boolean singleton = true;
- private DomTool tool;
- public void setSingleton(boolean singleton) {
- this.singleton = singleton;
- }
- public Object createTool() throws Exception {
- if (this.singleton) {
- if (tool == null) {
- tool = new DomTool();
- }
- return tool;
- } else {
- return new DomTool();
- }
- }
- public boolean isSingleton() {
- return this.singleton;
- }
- }
3.暴露服务工具
[html] view plain copy
- <services:pull>
- <pull-factories:factory id="domTool"
- class="com.alibaba.sample.petstore.web.common.util.MyToolFactory" />
- </services:pull>
4.vm中使用
[html] view plain copy
- $domTool.addScript("scripts/test.js");
最后欢迎大家访问我的个人网站:1024s