📄 ch1.html
字号:
<p>Anyway, run the application and you should see. <br>
总之,运行该应用而且你应该可以看到(改变生效了)。</p>
<p class="style2"> Disabling caching in Tapestry <br>
禁用Tapestry的缓存功能</p>
<p>It is troublesome to reload the application before each test run. To solve the first part of the problem, you can tell <br>
Tapestry to not to cache HTML and .page files. To do that, you need to set a JVM system property </p>
<p>page 026</p>
<p>org.apache.tapestry.disable-caching to true. If you were starting the JVM yourself, you would run it like: <br>
每次测试运行前重新加载应用很麻烦。要解决这个问题的第一部分,你可以告诉Tapestry不要缓存HTML和.page文件。要那样,你需要把一个JVM系统属性org.apache.tapestry.disable-caching设置为true。如果你一直自己启动JVM,你可以这样运行它:</p>
<p>java -Dorg.apache.tapestry.disable-caching=true ...</p>
<p>However, as the JVM is started by Tomcat, you need to setup a environment variable JAVA_OPTS before running <br>
startup.bat: <br>
然而,由于JVM是被Tomcat启动的,你需要在运行startup.bat之前设置一个环境变量JAVA_OPTS:<br>
<img src="ch1/1-26.jpg"/>
<p>Now, you can change say Home.html and the change will take effect immediately. For example, modify it as: <br>
现在,你可以改变比如Home.html并且改变会立刻生效。例如,像这样修改:</p>
<p> <html><br>
Hello <span jwcid="subject">world</span>! <b>Good!</b><br>
</html></p>
<p>Then run the application: <br>
然后运行应用:<br>
<img src="ch1/1-27.jpg"/>
<p class="style2"> Making changes to Java code take effect <br>
使Java代码的改变生效</p>
<p>What about changes to Java code? If you modify Home.java like: <br>
改变Java代码会怎么样呢?如果你这样修改Home.java:<br>
<img src="ch1/1-7-d.jpg"/>
<p> public class Home extends BasePage {<br>
public String getGreetingSubject() {<br>
return "<del>John</del><b>Paul</b>";<br>
}<br>
}</p>
<p>Run the application again. You will still see "Hello John". To solve this problem, you can tell Tomcat to reload the whole application if any of its classes is changed. This is done by marking the application as reloadable in the context descriptor (c:\tomcat\conf\Catalina\localhost\HelloWorld.xml): <br>
在此运行应用。你将仍然看到“Hello John”。要解决这个问题,你可以告诉Tomcat,如果它的任何类文件被改变了,立刻重新加载整个应用。这可以通过在上下文描述符中将应用标记为reloadable实现(c:\tomcat\conf\Catalina\localhost\HelloWorld.xml):</p>
<p> <Context<br>
docBase="c:/workspace/HelloWorld/context"<br>
path="/HelloWorld"<br>
<b>reloadable="true"</b>/></p>
<img src="ch1/1-28.jpg"/>
<p>Now, reload the application so that Tomcat reads the context descriptor (and learns that the application is now reloadable). Then try to change the Java code again and reload the page. It will work. It may not take effect immediately, but it may take just a few seconds to reload. <br>
现在,重新加载应用以便Tomcat读取上下文描述符(并且知道该应用现在是reloadable的)。然后试着再次改变Java代码并且重新加载该页。它将起作用。可能不会立刻生效,因为需要一点时间去重新加载。</p>
<p>page 027</p>
<p class="style2"> Other ways to set the value <br>
设置值的其他方法</p>
<p>Instead of calling getGreetingSubject(), there are other ways to achieve the same output effect. For example, modify <br>
Home.page: <br>
存在其他的方法获得同样的输出效果,而不是调用getGreetingSubject()。例如,修改Home.page:<br>
<img src="ch1/1-8-d.jpg"/>
<p> <page-specification><br>
<component id="subject" type="Insert"><br>
<binding name="value" value="ognl:<b>'Paul'</b>"/><br>
</component><br>
</page-specification><br>
解释:<br>
It is still an OGNL expression, but the string is quoted, so it is a string constant. <br>
这仍是一个OGNL表达式,不过字符串被引用了,所以是个字符串常量。<br>
</p>
<p>Now run it again it should say "Hello Paul". If not, the change is cached by Windows. In that case, you can make any change the Home.page file again such as adding a space and deleting it again. Finally, save it again. Then the change should take effect. <br>
现在再次运行它,会产生“Hello paul”。如果不是,改变被Windows缓存了。那种情况下,你可以再次对文件Home.page做些改变,比如增加一个空格再删除。最后,保存。然后改变将会生效。</p>
<p>There is yet another alternative: <br>
还有其他的可选方法:<br>
<img src="ch1/1-9-d.jpg"/>
<p> <page-specification><br>
<component id="subject" type="Insert"><br>
<binding name="value" value="<b>literal:Judy</b>"/><br>
</component><br>
</page-specification> <br>
解释:<br>
What is following is no longer an OGNL expression, but a string literal.<br>
其后不再是OGNL表达式,而是个字符串字面量。<br>
It is just a string literal. No need to quote it. <br>
它只是个字符串字面量。不需要引用它。<br>
</p>
<p>In fact, you don't have to provide a prefix: <br>
实际上不需要提供前缀:<br>
<img src="ch1/1-10-d.jpg"/>
<p> <page-specification><br>
<component id="subject" type="Insert"><br>
<binding name="value" value="<b>greetingSubject</b>"/><br>
</component><br>
</page-specification><br>
解释:<br>
No prefix is specified. In that case the Tapestry will assume that it is an OGNL expression as if ognl prefix was used. <br>
没有指定前缀。此时,由于没有使用ognl前缀,Tapestry将假定它是个OGNL表达式。<br>
</p>
<p class="style2"> Debugging a Tapestry application <br>
调试Tapestry应用</p>
<p>To debug your application in Eclipse, you need to set two more environment variables for Tomcat and launch it in a <br>
special way: <br>
要在Eclipse中条是你的应用,你需要为Tomcat再设置两个环境变量并以一种特殊的方式启动它:<br>
<img src="ch1/1-29.jpg"/>
</p>
<p>Note that you're now launching it using catalina.bat instead of startup.bat. This way Tomcat will run the JVM in debug mode so that the JVM will listen for connections on port 8000. Later you'll tell Eclipse to connect to this port. <br>
注意,你现在使用catalina.bat代替startup.bat启动。这样一来,Tomcat将以调试模式运行JVM,由此JVM将监听端口8000上的连接。稍后你会告诉Eclipse连接这个端口。</p>
<p>Now, set a breakpoint here: <br>
现在,这儿设置一个断点:</p>
<p>page 028</p>
<img src="ch1/1-30.jpg"/>
<p>Change the OGNL expression back: <br>
将OGNL表达式改回去:</p>
<p> <page-specification class="com.ttdev.helloworld.Home"><br>
<component id="subject" type="Insert"><br>
<binding name="value" value="<b>greetingSubject</b>"/><br>
</component><br>
</page-specification><br>
</p>
<p>Choose "Debug": <br>
选择“调试”:<br>
<img src="ch1/1-31.jpg"/>
<p>The following window will appear:<br>
接下来的窗口将出现:<br>
<img src="ch1/1-32.jpg"/>
<p>Right click "Remote Java Application" and choose "New". Browse to select your HelloWorld project and make sure the port is 8000: <br>
右击“远程Java应用”并选择“新建”。浏览以选择你的HelloWorld工程并确保端口是8000:</p>
<p>page 029<br>
</p>
<img src="ch1/1-33.jpg"/>
<p>Click "Debug" to connect to the JVM in Tomcat. Now go to the browser to load the page again. Eclipse will stop at the breakpoint: <br>
点击“调试”以连接Tomcat中的JVM。现在转向浏览器,重新加载页面。Eclipse将停在断点处:<br>
<img src="ch1/1-34.jpg"/>
<p>Then you can step through the program, check the variables and whatever. To stop the debug session, choose the process and click the Stop icon: <br>
接着你可以单步调试该程序,查对变量或者随便什么。要停止调试会话,选择该进程并点击“停止”图标:</p>
<p>page 030</p>
<img src="ch1/1-35.jpg"/>
<p>Having to set all those environment variables every time is not fun. So, you may create a batch file c:\tomcat\bin\tap.bat: <br>
每次不得不设置所有的这些环境变量并不有趣。所以,你可以创建一个批处理文件c:\tomcat\bin\tap.bat: :</p>
<p> set JAVA_OPTS="-Dorg.apache.tapestry.disable-caching=true"<br>
set JPDA_ADDRESS=8000<br>
set JPDA_TRANSPORT=dt_socket<br>
catalina jpda start</p>
<p>Then in the future you can just run it to start Tomcat. <br>
那么以后你可以只通过运行它来启动Tomcat。</p>
<p class="style2"> Summary <br>
总结</p>
<p>To develop a Tapestry, you can install Tomcat and Eclipse. <br>
要开发一个Tapestry应用,你可以安装Tomcat和Eclipse。</p>
<p>To install Tapestry, you need to get some other libraries. Then copy the jar files into Tomcat's shared lib folder so that they are available to all web applications. <br>
要安装Tapestry,你需要取得一些其他的库。然后把jar文件拷贝到Tomcat的共享库目录中,以使它们可为所有的web应用可用。</p>
<p>To register a web application with Tomcat, you need to create a web.xml file and a context descriptor to tell Tomcat <br>
where the application's files can be found. <br>
要在Tomcat中注册一个应用,你需要创建一个web.xml文件和一个上下文描述符,用来告诉Tomcat可以在哪儿找到应用的文件。</p>
<p>To use a Tapestry application, you can enter a URL to ask Tapestry to display a certain page. If you don't specify <br>
anything particular in the URL, it will display the Home page. <br>
要使用一个Tapestry应用,你可以输入一个URL让Tapestry显示特定的页面。如果没有在URL中指定任何特别的东西,将显示Home页。</p>
<p>When displaying a certain page, Tapestry will check the .page file (page specification) to find out the Java class of the page object and create it. The page object will read its HTML file (the template) and basically output what's in the HTML file. But if there is a component in the HTML file, it will check the .page file to find out the type of the component, then create the component (a Java object) and ask it to output HTML for itself. <br>
当显示某页时,Tapestry将检查对应的.page文件(页面规范)以找出页面对象的类并创建它。页面对象将读取其HTML文件(模板),然后主要是输出HTML文件的内容。但是,如果HTML中有组件,它将检索.page文件找出组件的类型,然后创建该组件(Java对象)并要它为自己输出HTML。</p>
<p>An Insert component will output some plain text as HTML code. It evaluates its "value" parameter which is bound to a <br>
certain expression. The expression may have an OGNL expression (with an ognl prefix) or a string literal (with a literal prefix). If no prefix is specified, Tapestry will always assume that it is an OGNL expression. For an OGNL expression, if the expression is "foo", it will call getFoo() on the page object and expect the return value to be a string to output. <br>
Insert组件将输出一些纯文本作为HTML代码。它计算自己的“value”参数,该参数被绑定到某个表达式。该表达式可能有一OGNL表达式(带有前缀ognl)或者一字符串字面量(带有前缀literal)。如果没有指定前缀,Tapestry将总是把它作为OGNL表达式。对于OGNL表达式“foo”,它将调用页面对象的getFoo()并且预期获得一个字符串作为返回值以供输出之用。</p>
<p>If you make changes to your HTML file or .page files, your application won't see the changes by default because Tapestry is caching them. To solve the problem, set a JVM parameter to disable the cache. Similarly, if you make changes to your Java class, your application won't see the changes because Tomcat is caching them. To solve the problem, mark the application as reloadable in the context descriptor so that the application is reloaded automatically if any of its Java code is changed. <br>
缺省地,如果你的HTML文件或者.page文件改变了,应用将看不出变化,因为Tapestry缓存了它们。要解决这个问题,设置一个JVM参数禁用缓存功能。类似地,如果你的Java文件改变了,应用将看不出变化,因为Tomcat缓存了它们。在上下文描述符中标记应用为reloadable可解决问题,这样一来,Java代码发生任何变化应用都将自动被重新加载。</p>
<p>To debug a Tapestry application, tell Tomcat to run the JVM in debug mode, set a breakpoint in the Java code and make a Debug configuration in Eclipse to connect to that JVM. <br>
要调试Tapestry应用,告诉Tomcat以调试模式运行JVM,在Java代码中设置断点并在Eclipse中做一个调试配置以连接该JVM。<br>
</p>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -