How to configure components, their type, which methods of the page class to call to provide them information – all these details are provided in the page specification. Today you are going to see more components of those most often used in Tapestry application, and you are going to learn some important concepts related to them. First of all, we shall experiment with that very simple Tapestry application created in the previous article, but then we shall start working on another project, which is slightly more complex. Implicit components Launch your NetBeans and open the FirstTapestry project we’ve created in the previous article. Let’s concentrate on how we have configured the Insert component used in this project. First of all, we used a standard <span> HTML element and marked it as a Tapestry component: <span jwcid="now">…</span> We have also given a name to this component, now. If you don’t like this name, use any other name; there's no problem with that. And then, to define what this component actually is, we have configured it in the page specification: <component id="now" type="Insert"> <binding name="value" value="currentDate"/> </component> This is what we did in the previous article. There is, however, an alternative way to achieve the same goal. Let’s change the Home.html template to look like this (I am showing only the line that should be changed): <p>Now is <span jwcid="@Insert" value=”ognl:currentDate”>8:27, the 1st of April 2007</span>.</p> Then remove the Insert component configuration from Home.page, and leave the page specification empty: <?xml version="1.0"?> <!DOCTYPE page-specification PUBLIC "-//Apache Software Foundation//Tapestry Specification 4.0//EN" "http://tapestry.apache.org/dtd/Tapestry_4_0.dtd"> <page-specification class="com.devshed.tapestry.first.Home">
</page-specification> Press F6 to run the project and make sure that it works exactly as before. In some cases, after making a change in an HTML template, you will not see your change immediately reflected in the running application. This is because, by default, Tapestry caches page templates for higher efficiency. See the How to disable caching section in the next article for an explanation of how to change settings and make your application more responsive during development. Let’s see what we have done here. In the page template, instead of giving a name to our one and only component, we have directly specified its type: Insert. The ‘@’ symbol in front of the component type tells Tapestry that this is a type of component and not just a name that we have chosen for it. Now the page class will know immediately what kind of component we have used. But which method should it invoke to provide data to this component? The piece of information which was previously contained in the <binding> element of page specification: <binding name="value" value="currentDate"/> has turned into an additional attribute of <span> element: value=”ognl:currentDate” Clearly, there is no need to provide any details in the Home.page file anymore, so we have left the page specification empty. This way of configuring Tapestry components (everything moves to the page template, nothing is left for the page specification) is termed “an implicit component” as opposed to the “declared component” we’ve dealt with before. However, I hear you asking the question: why in one case did we use “curentDate”, while in the other case we used “ognl:currentDate”? And what exactly does this ‘ognl:’ prefix mean?
blog comments powered by Disqus |
|
|
|
|
|
|
|