Summary
Definitions
Overview
Illustration 1
-Illustration 2-
Illustration 3
The Framework - a flyby
Conclusion
Biography
Resources
|
Illustration 2
If you thought the previous illustration was a lot of work to show a
simple welcome page, don't fret; this illustration is for you.
Here, we'll use the same Insert JWC as in Listing
1, but we'll use it to show the user's visitng time
instead. Before we continue, let me boost your spirits by showing you
the code that is needed for this illustration.
Page Template
<html>
<head>
<title>Welcome to Tapestry!</title>
</head>
<body>
Hello Jack! Welcome to Tapestry!
Your visiting time is <span jwcid="now@Insert" value="ognl:new java.util.Date()">Current time</span>
</body>
</html>
Listing 6. Home.html
That's all we need for this illustration, of course other than the
web.xml which we can reuse from the previous illustration.
You don't need the page specification or the JavaBeans component
class; neither do you need the application specification. The framework
has default values defined for all these parts; we'll talk about
these a little later, but for now let's focus our attention on the
template.
The template, if you notice, looks pretty much the same as in
Listing 1 except for the placeholder tag. The placeholder tag now
has the component type (Insert ) embedded into the
jwcid attribute value using the @ symbol. This is
just another notation for declaring a component. A component thus
declared is known as an Implicit component. now is the
unique ID for the component and may be omitted if you don't have
the need to reference this component in your code. If the ID is
omitted, the component is called an "Anonymous Implicit"
component, and the framework would provide an arbitrary ID to such
components for internal use. An Implicit component has to be declared
and configured in the placeholder tag in its entirety thus avoiding the
need for a separate specification. Parameters of Implicit JWCs are
bound to their values right in the placeholder tag in the form of
attribute-value pairs. So the value parameter of the
Insert JWC, in our example, is bound to an instance of
java.util.Date , as shown in Listing 6, using OGNL.
Yes, OGNL expressions are perfectly acceptable for attribute values in
templates. Any attribute value prefixed with ognl: is
considered an OGNL expression. This type of binding is identical, in
meaning, to the binding specified in the Page specification from our
previous illustration.
The component declaration was only one part of our Page specification,
the other parts being the Page class declaration
(demo.Home ) and the template declaration
($template asset). The framework by default searches for
the template by the name of the component with a .html
extension, so we can skip the $template declaration. We
also do without the Page class, and thus the Page specification itself,
with the help of the framework default Page class,
org.apache.tapestry.html.BasePage . The missing application
specification is also owed to the framework's default behavior.
Knowing that the framework will forward all unknown requests to a Page
component named Home , we skip the application
specification too. Another point worth mentioning here is that the
framework has the ability to search and locate pages and templates not
explicitly specified in the specification. The framework performs this
search in a methodical fashion, the details of which can be found in
the JavaDocs of
org.apache.tapestry.resolver.PageSpecificationResolver and
org.apache.tapestry.engine.DefaultTemplateSource classes.
Now, if we place our template (Home.html ) under the
application context Welcome , and place the
web.xml file under the WEB-INF folder, and ran our
Welcome example application within Tomcat, running at port 8080, the
request URL http://localhost:8080/Welcome/app will take
us to the Home Page of our Welcome application that we just built.
|