On 3/4/08, Sebastiaan van Erk <[EMAIL PROTECTED]> wrote:
> I do basically the same thing, but since the title does not change on my
> pages I see no need to have a (dynamic) model for the property, plus I
> just use the constructor to set it, which saves some loc. In other words:
>
>
> public abstract class BasePage extends WebPage
> {
> // ...
>
> public BasePage(String title)
> {
> add(new Label("title", title));
>
> }
> }
>
> public class SubPage extends BasePage
> {
>
> public SubPage(PageParameters parameters) {
> super("whatever title");
> }
> }
>
> If you need the page parameters in the BasePage constructor then feel
> free to pass them with the constructor too...
>
> Regards,
>
> Sebastiaan
>
The problem with this approach is that you're not able to localize the
title if you hard-code it. What I've done is actually specify a key
for my messages file and I use that. So, every page has to define its
page.title key in its PageClass.properties file.
>
> Kaspar Fischer wrote:
> > I am using markup inheritance (<wicket:child> and <wicket:extend>) and
> > need to set the
> > page title from my subpage. I currently add a label in the base class
> > (BasePage.java)
> > and make it use an abstract method getTitle(), which is overridden in
> > the subclass
> > (SubPage.java). Has anybody found a better way?
> >
> > Here's my solution:
> >
> > <!-- BasePage.html -->
> > <html>
> > <head>
> > <title wicket:id="title">[Page title]</title>
> > </head>
> > <body>
> > <wicket:child/>
> > </body>
> > </html>
> >
> > <!-- SubPage.html -->
> > <wicket:extend>
> > <!-- anything ... -->
> > </wicket:extend>
> >
> >
> > public abstract class BasePage extends WebPage
> > {
> > // ...
> > public BasePage(final PageParameters parameters)
> > {
> > add(new Label("title", new PropertyModel(this, "title")));
> > }
> > public abstract String getTitle();
> > }
> >
> > public class SubPage extends BasePage
> > {
> > // ...
> > public String getTitle()
> > {
> > return "whatever title";
> > }
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]