dwr.xml结构
2016-01-07 00:00
92 查看
摘要: 描述dwr.xml的常用属性作用
The create element in your dwr.xml file has the following structure.
Most of these elements are optional - All you really need is to specify the creator and javascript attributes.
The creator attribute is required - it specifies which creator will be used.
The following Creators are available in DWR:
new: Which uses the Java 'new' operator.
static: Which uses the 'getInstance()' method (by default) to obtain an instance of the class.
none: This does not create objects. See below for why. (v1.1+)
scripted: Uses a scripting language like BeanShell or Groovy via BSF.
spring: Gives access to beans through the Spring Framework.
jsf: Uses objects from JSF. (v1.1+)
struts: Uses struts FormBeans. (v1.1+)
pageflow: Gives access to a PageFlow from Beehive or Weblogic. (v1.1+)
ejb3: An experimental Creator to give access to EJB3 session beans. This code should not be seen as production quality until it has undergone more testing, and has an official maintainer. (v2.0+)
Should you need to write your own creator, you must register it using the
The javascript attribute is required - it gives your newly created object a name in the browser. You should avoid using JavaScript reserved words.
The scope attribute is largely the same as the scope attribute as defined by the servlet spec. It allows you to specify what a bean is available to. The options are "application", "session", "request", "page" and an additional scope "script". The first 4 of these values should be familiar to Servlet and JSP developers. "script" scope allows you to have something similar to an HTTP session that is tied to an ID in a page rather than in a cookie.
The scope attribute is optional. It defaults to "page".
The param element is used by the various creators for specific bits of configuration. For example the 'new' creator needs to be told what type of object to call 'new' on. The parameters that are available to each creator are specified in the documentation for that creator. See the list above for links.
The include and exclude elements allow a creator to restrict access to class methods. A Creator should specify EITHER a list of include elements (which implies that the default policy is denial) OR a list of exclude elements (which implies that the default policy is to allow access)
For example to deny access to all methods in some class except for the
The default visibility is that having added a class to a 'create' element, all its methods are accessible.
The auth element allows you to specify a J2EE role level for further access control checking:
You might be using a scope other than "page" (see above) and have arranged to pre-populate the scope with the given object. In this case no object creation is required.
Alternatively the method to call is static in which case no object is required. DWR does a check for static methods before deciding if it needs to call the creator.
For both of these options you will need a param element - "class". This tells DWR what type it is working on.
An alernative approach is to create an instance of the object using BeanShell and BSF. See the section on the 'Scripted' Creator for more details.
The Creators
Creators are an integral part of DWR and are responsible for exposing the methods on Java classes to the client.The create element in your dwr.xml file has the following structure.
<allow> <create creator="..." javascript="..." scope="..."> <param name="..." value="..."/> <auth method="..." role="..."/> <exclude method="..."/> <include method="..."/> </create> ... </allow>
Most of these elements are optional - All you really need is to specify the creator and javascript attributes.
The creator attribute is required - it specifies which creator will be used.
The following Creators are available in DWR:
new: Which uses the Java 'new' operator.
static: Which uses the 'getInstance()' method (by default) to obtain an instance of the class.
none: This does not create objects. See below for why. (v1.1+)
scripted: Uses a scripting language like BeanShell or Groovy via BSF.
spring: Gives access to beans through the Spring Framework.
jsf: Uses objects from JSF. (v1.1+)
struts: Uses struts FormBeans. (v1.1+)
pageflow: Gives access to a PageFlow from Beehive or Weblogic. (v1.1+)
ejb3: An experimental Creator to give access to EJB3 session beans. This code should not be seen as production quality until it has undergone more testing, and has an official maintainer. (v2.0+)
Should you need to write your own creator, you must register it using the
<init>section.
The javascript attribute is required - it gives your newly created object a name in the browser. You should avoid using JavaScript reserved words.
The scope attribute is largely the same as the scope attribute as defined by the servlet spec. It allows you to specify what a bean is available to. The options are "application", "session", "request", "page" and an additional scope "script". The first 4 of these values should be familiar to Servlet and JSP developers. "script" scope allows you to have something similar to an HTTP session that is tied to an ID in a page rather than in a cookie.
The scope attribute is optional. It defaults to "page".
The param element is used by the various creators for specific bits of configuration. For example the 'new' creator needs to be told what type of object to call 'new' on. The parameters that are available to each creator are specified in the documentation for that creator. See the list above for links.
The include and exclude elements allow a creator to restrict access to class methods. A Creator should specify EITHER a list of include elements (which implies that the default policy is denial) OR a list of exclude elements (which implies that the default policy is to allow access)
For example to deny access to all methods in some class except for the
setWibble()method you should put the following into your dwr.xml
<create creator="new" javascript="Fred"> <param name="class" value="com.example.Fred"/> <include method="setWibble"/> </create>
The default visibility is that having added a class to a 'create' element, all its methods are accessible.
The auth element allows you to specify a J2EE role level for further access control checking:
<create creator="new" javascript="Fred"> <param name="class" value="com.example.Fred"/> <auth method="setWibble" role="admin"/> </create>
The 'none' Creator
The none creator does not do any object creation - it makes the assumption that you don't need one. This might be true for 2 reasons.You might be using a scope other than "page" (see above) and have arranged to pre-populate the scope with the given object. In this case no object creation is required.
Alternatively the method to call is static in which case no object is required. DWR does a check for static methods before deciding if it needs to call the creator.
For both of these options you will need a param element - "class". This tells DWR what type it is working on.
Using static methods
DWR does a check before calling any Creators to see if the method to be called is static. If it is then the Creator is not called. Clearly this logic will work with any creator, however the 'null' Creator is easiest to configure.Using Singletons
The static creator is the recommended approach for using Singletons.An alernative approach is to create an instance of the object using BeanShell and BSF. See the section on the 'Scripted' Creator for more details.
Other Creators
We have occasional requests for new creators, the most common is for an EjbCreator. The best place to discuss new creators is the DWR mailing list.相关文章推荐
- js调试method
- 关于云计算与大数据的真相(干货整理:资料+视频)
- Developer Disk Image
- OC高效率52之对象内部尽量直接访问实例变量
- OC 之BOLCK
- foundation之结构体
- Foundation框架之集合
- OC之 block 本质
- Android屏幕自动变换,layout-land文件修改报错
- 天下数据浅谈服务器存储加速器四点独特应用
- 创业的第一百零三天
- CI学习一:maven项目自动部署到tomcat
- spring源码阅读笔记(二)——自定义标签
- ecshop,里的{$search_keywords|escape}在哪里设置
- ecshop广告调用
- iOS App设置icon,启动图,App名称的方法
- 多线程并发流程控制之dispatch_group 有关函数
- 跟着MJExtension实现简单的字典转模型框架 - 简书
- PCA的概念
- Windows系统下安装配置Nginx