On 3/4/08, Hoover, William <[EMAIL PROTECTED]> wrote:
> public abstract class BasePage extends WebPage {
>         public BasePage(final PageParameters parameters) {
>
>                 // If the title is not set in any sub-pages this will be the 
> default
>                 setTitle(new StringResourceModel("base.page.title", this, 
> null));
>         }
>
>         protected final void setTitle(final StringResourceModel srm) {
>                 addOrReplace(new Label("title", srm));
>
>         }

How about this:

          protected final void setTitle(IModel titleModel) {
                addOrReplace(new Label("title", titleModel));
          }

That way, you can calculate your title from anything you want.

>  }
>  <!-- BasePage.html -->
>  <html>
>         <head>
>                 <title wicket:id="title">[Page title]</title>
>         </head>
>         <body>
>                 <wicket:child/>
>         </body>
>  </html>
>
>
>
>
>
> public final class SubPage extends BasePage {
>         public BasePage(final PageParameters parameters) {
>                 setTitle(new StringResourceModel("sub.page.title", this, 
> null));
>
>         }
>  }
>  <!-- SubPage.html -->
>  <wicket:extend>
>         <!-- anything ... -->
>  </wicket:extend>
>
>
> -----Original Message-----
>  From: [EMAIL PROTECTED]
>  [mailto:[EMAIL PROTECTED] Behalf Of James Carman
>  Sent: Tuesday, March 04, 2008 10:53 AM
>  To: [email protected]
>  Subject: Re: Page title when using markup inheritance
>
>
>  On 3/4/08, Sebastiaan van Erk <[EMAIL PROTECTED]> wrote:
>  > James Carman wrote:
>  >
>  >  > 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.
>  >
>  >
>  > That's what I do it too. :-) In applications that are localized I change 
> the
>  >
>  >
>  >  add(new Label("title", title))
>  >
>  >
>  > with
>  >
>  >  add(new Label("title", new StringResourceModel(titleKey, this, new
>  >  CompoundPropertyModel(this)));
>
>  Very nice!  I like the fact that you can do substitutions with this.
>  I had that problem on the back burner in my brain until I needed to
>  solve it.  But, you took care of it for me.  Thanks!
>
>  >
>  >  This has the added benefit that you can do nice property substitutions,
>  >  that is, if the titleKey resolves to "Profile for ${session.userName}"
>  >  then you'll get a nice title "Profile for Sebastiaan" dynamically. :-) I
>  >  don't use a static key though (like page.title) because my keys come
>  >  from the database and I have little web page with a tree view where you
>  >  can edit the key values. :-)
>  >
>  >  Regards,
>  >
>  > Sebastiaan
>  >
>  >
>  >  >>  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]
>  >  >
>  >
>  >
>
>  ---------------------------------------------------------------------
>  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]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to