由于没有《Enjoying web development with tapestry 4.1》的文档,只能按照4.0里面的内容去测试。
对应书上例子:304页-311页。
Home.html:
xml 代码
- <html>
- <body jwcid="@Body">
- <form jwcid="@Form" action="http://www.foo.com">
- <input jwcid="deleteButton@Submit" type="submit" value="Delete"/>
- <span jwcid="insertConfirmScript"/>
- form>
- body>
- html>
Home.page:
xml 代码
- xml version="1.0"?>
- "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
- "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd">
- <page-specification>
- <component id="insertConfirmScript" type="Script">
- <binding name="script" value="literal:Confirm.script"/>
- <binding name="msg" value="literal:Are you sure?"/>
- <binding name="button" value="components.deleteButton"/>
- component>
- page-specification>
Confirm.script:
xml 代码
- xml version="1.0" encoding="gb2312"?>
- "-//Apache Software Foundation//Tapestry Script Specification 3.0//EN"
- "http://jakarta.apache.org/tapestry/dtd/Script_3_0.dtd">
- <script>
- <input-symbol key="msg" required="yes"/>
- <input-symbol key="button" required="yes"/>
- <let key="funcName" unique="yes">getConfirmationlet>
- <body>
- function ${funcName}(){
- return confirm("${msg}");
- }
- body>
- <initialization>
- document.${button.form.name}.${button.name}.onclick=${funcName};
- initialization>
- script>
运行后的源码:
xml 代码
- <html>
- <body id="Body">
- <script type="text/javascript">
- function getConfirmation(){
- return confirm("Are you sure?");
- }
- // -->script>
- <form method="post" action="/ConfirmDelete/app" id="Form">
- <div style="display:none;" id="Formhidden"><input type="hidden" name="formids" value="deleteButton" />
- <input type="hidden" name="component" value="$Form" />
- <input type="hidden" name="page" value="Home" />
- <input type="hidden" name="service" value="direct" />
- <input type="hidden" name="submitmode" value="" />
- <input type="hidden" name="submitname" value="" />
- div>
- <input type="submit" name="deleteButton" id="deleteButton" value="Delete" />
- form>
- <script type="text/javascript">
- dojo.addOnLoad(function(e) {
- dojo.require("tapestry.form");tapestry.form.registerForm("Form");
- document.Form.deleteButton.onclick=getConfirmation;
- tapestry.form.focusField('deleteButton');});
- // -->script>body>
- html>
在IE中运行提示script错误:
java 代码
- 行:24
- 字符:1
- 代码:0
- 错误:'dojo' 未定义
- 网址:http://localhost:7856/ConfirmDelete/app
和文档中的例子产生的页面代码不一致的地方在于最后几行。
文档中:
xml 代码
- <script language="JavaScript" type="text/javascript">
- var $Form_events = new FormEventManager(document.$Form);
- document.$Form.deleteButton.onclick=getConfirmation;
- focus(document.$Form.deleteButton);
- // -->script>
中间还有一些差别,先不管了!
运行后,点击按纽没有任何反应。
请问各位大大,4.1.2中使用script还需要哪一些配置?(动态绑定组件事件时才会出错,事先传入组件名不会出错!)
知道的请告诉我,再次谢过了!