JavaScud | Forum | JIRA | Blog |
  Dashboard > DWR中文文档 > ... > Creators > Scripted Creator
  DWR中文文档 Log In View a printable version of the current page.  
  Scripted Creator
Added by 黑灵, last edited by 黑灵 on Oct 18, 2006
Labels: 
(None)

'scripted' 创造器

new创造器在DWR中已经默认声明了:<creator id="script" class="uk.ltd.getahead.dwr.create.ScriptedCreator"/>

这个创造器用BSF来执行脚本得到Bean,例如:

<allow>
  ...
  <create creator="script" javascript="EmailValidator">
    <param name="language" value="beanshell"/>
    <param name="script">
      import org.apache.commons.validator.EmailValidator;
      return EmailValidator.getInstance();
    </param>
  </create>
  ...
</allow>

script创造器有如下参数:

参数 DWR版本 描述
language 1.0 脚本语言,字符串,例如'beanshell'. (必需)
script 1.0 要执行的脚本。 (必需,除非scriptPath参数存在)
scriptPath 1.1 脚本文件路径。 (必需,除非script参数存在)
reloadable 1.1 是否检测脚本文件的改动,以重新加载 (可选, 默认true)
class 1.0 创造出对象的类型(可选). 如果没有DWR通过创造器得到类型。

需要了解的主题

要使用这个创造器,你需要把一些辅助库放到WEB-INF/lib文件夹下:BSF的jar包,你要用的脚本语言的jar包

当一个类是用script创造出来的,并且scope是session或application,如果你的脚本改变,session中的类和script中的类就不一致了。这样会出现错误。虽然web容器不用重启,但是用户需要先登出(或以某种方式清空session),然后再登录。

当clazz参数不为空,并且用来创造新实例,DWR简单的调用 class.newInstance() 方法。这种方法是没问题的,除非脚本正在用某个参数创建一个类,或者调用某个函数来配置这个类。 不幸的是,每次请求都要重新运行script并造成上面的问题。

Site running on a free Atlassian Confluence Open Source Project License granted to WebWork China. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.3 Build:#808 May 29, 2007) - Bug/feature request - Contact Administrators