SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 245 | Next

Alexander Kolesnikov

"Tapestry 5: Building Web Applications"


Using a Parameter
The most natural solution for displaying a page-specific title is to pass this title to
the Border component as a parameter, and this is very easy to do. First of all, let's
prepare the component's template to display the title:

Celebrity Collector: ${pageTitle}
href="${asset:context:/assets/styles.css}"
type="text/css"/>
??¦
Creating Custom Components
[ 204 ]
Next, we need to define the parameter in the component class. Add the following
lines of code to Border.java:
@Parameter(required = true, defaultPrefix = "literal")
private String pageTitle;
public String getPageTitle()
{
return pageTitle;
}
The parameter is defined as mandatory here, which probably makes sense. If it is not
provided to the component, Tapestry will throw an exception. However, we could
also define it as optional and then perhaps provide a default value, like this:
@Parameter
private String pageTitle = "Default Title";
Also, we have defined that the default prefix for this parameter is literal, otherwise it literal, otherwise it
will be prop.
Finally, we need to add this parameter to the Border component on all pages. Here
is how it will look for the ShowAll page, as an example:
t:pageTitle="All Celebrities in Collection" xmlns:t="http://
tapestry.


Pages:
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
druga wojna światowa Free English grammar and study guid hotel jelenia góra Russian bride counter strike 1.6