1

I'm porting our existing web application from Wicket 1.4 to 1.5. In the app there are two template pages which are children of a base page. The templates are named secure and unsecure, and they define pages for authenticated and unauthenticated users. Any pages in the app inherit from these templates. In Wicket 1.4 this set up worked fine without any problems.

After porting to Wicket 1.5 I get the following error:

Unable to find component with id 'PageTitle' in [HtmlHeaderContainer]

'PageTitle' is a Wicket Label and is used dynamically build the page title in the base page, it is positioned in the <head> tag of the base page mark up. What I've discovered is that the <head> mark up is being rendered twice, so I presume I get the error because Wicket creates the PageTitle once and then tries to create it again (The <head> is defined in the base page mark up only).

The quick and dirty fix is to move the PageTitle to the templates (duplicated code). Is there a better way to solve this problem?

Hopefully my description is clear enough, however, I can supply a code example if needed.

Simon Adcock
  • 3,554
  • 3
  • 25
  • 41
sardo
  • 2,731
  • 3
  • 19
  • 18

2 Answers2

0

The <head> tag should only be used once in page markup. This means that if you have a <head> tag in a base page, no page that extends it should include it. Further, no component should use the <head> tag.

Instead, use the <wicket:head> tag to include any additional content that is not included in your base page. Wicket will use the <wicket:head> tag to dynamically inject content into the <head> tag that is rendered and delivered to the browser.

Daniel Semmens
  • 461
  • 2
  • 4
  • OK thanks, I think we're doing that (apart from which I need to review...if it can be avoided I think it's best to avoid adding stuff to the head via java code) – sardo Jun 29 '12 at 09:42
  • ultimately it's all added via javacode in wicket as the java is parsing through your html files, step by step, and rendering a response that will be returned to the browser. In the case of the and tags, they generate a HtmlHeaderResolver (http://ci.apache.org/projects/wicket/apidocs/1.5.x/org/apache/wicket/markup/resolver/HtmlHeaderResolver.html) component which manages merging content together to be rendered to one tag. – Daniel Semmens Jun 29 '12 at 11:24
0

OK as requested here's a code sample. BasePage.java:

public class BasePage extends WebPage 
{

  public BasePage() 
  {
     this(new PageParameters());
  }

  public BasePage(PageParameters parameters)
  { 
    add(new Label("PageTitle", "Gosh Wicket version migration is hard work"));
  }
  ...

}

BasePage.html (doctype etc., removed):

<html>  
<head>
    <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
    <title wicket:id="PageTitle">Page title goes here</title>
    <!-- This comment will appears in both the headers I see in the source, therefore this header is rendering twice-->
    <link type="text/css" rel="stylesheet" href="css/application.css" />
    <script type="text/javascript" src="js/rollover.js"></script>
    <script type="text/javascript" src="js/menus.js"></script>
</head>

<wicket:child/>
</html>

UnSecureTemplate java:

public class UnSecureTemplate extends BasePage
{
  public UnSecurePageTemplate()
  {
      super(new PageParameters());
  }


  public UnSecureTemplate(PageParameters parameters) 
  {
    super(parameters);

    Label footerText = new Label("footerText", footerComesFromAPropertiesFile); 
    add(footerText);

    //Instance variables here defined in BasePage       
    // Header bar links - left
    Link<Object> hdrHome = addLink("hdrHome", HomePage.class);//this method is in BasePage in case you're wondering
    hdrHome.add(new Image("mgrLogo", new ContextRelativeResource(poLogoUrl)));

    // Header bar links - Right
    ExternalLink hdrCorporate = new ExternalLink("hdrCorporate", anExternnalLink);
    hdrCorporate.add(new Image("operatorLogo", new ContextRelativeResource(opLogoUrl)));
    add(hdrCorporate);
  }

UnSecureTemplate.html:

<wicket:extend xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">


<body id="body" onload="preloadImages(); return true;">

<div class="centerbody">
    <a name="top"></a>
    <div id="mast">
        <a wicket:id="hdrHome" title="home page">
            <img wicket:id="mgrLogo" id="mgr-logo" src="images/logoShort.png" width="171" height="45" wicket:message="alt:remon.logoAltText" /> 
        </a>
        <a wicket:id="hdrCorporate" title="Web Site">
            <img wicket:id="operatorLogo" id="po-logo" src="images/logoNoStrapline.png" height="45" wicket:message="alt:remon.logoAltText" />
        </a>
    </div>

    <div id="mainmenubar" style="width: 100%">
        <div class="menubaritem" style="width: 171px;">
            <a href="#">&nbsp;</a>
        </div>
        <div class="menubaritem" style="width: auto; border-right: none;">
            <a href="#">&nbsp;</a>
        </div>
    </div>

    <div id="mainpanel">
        <div id="leftnav">
            <p>&nbsp;</p>
        </div>

        <div id="rightpanel">

            <wicket:child/>

        </div> <!-- right panel -->
    </div> <!-- main panel -->

    <div id="footer" style="height:15px;">
        <span><a href="#top" style="text-decoration: none;" title="Back to Top"><span wicket:id="footerText">Footer Text</span></a></span>
    </div>
    <div id="footerspacer">
        &nbsp;
    </div>
</div> <!-- centre body -->

</body>
</wicket:extend>

}

An application page, LogIn.java:

public class Login extends UnSecureTemplate 
{


  public Login()  
  {
      this(new PageParameters());
  }

  public Login(PageParameters pageParameters) 
  {
    super(pageParameters);

    String welcomeResourceString = stringObtainedFromPropertiesFile;

    add(new Label("welcome", welcomeResourceString));
    add(new Label("loginHeader", thisAlsoComesFromPropertiesFile);

    LoginForm form = new LoginForm("loginform", new SimpleUser(), pageParameters);
    form.add(new FeedbackPanel("feedback"));
    add(form);
}

...

}

LogIn.html:

<wicket:extend xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">

<h2 wicket:id="welcome">Welcome to the Application</h2>

<div style="margin: 20px 150px 20px 150px; text-align: center;">
    <p wicket:id="loginHeader"></p>
    <form wicket:id="loginform" id="loginform" >
        <table style="display: table; border: 0px; margin: auto;" wicket:message="summary:loginTableSummary">
            <tr style="display: table-row;">
                <td class="login" colspan="2"><span wicket:id="feedback">Feedback</span></td>
            </tr>
            <tr style="display: table-row;">
                <td class="login">
                    <label for="username"><wicket:message key="username">Username</wicket:message></label>
                </td>
                <td class="login">
                    <input wicket:id="username" id="username" type="text" name="user" value="" size="30" maxlength="50"/>
                </td>
            </tr>
            <tr style="display: table-row;">
                <td class="login">
                    <label for="password"><wicket:message key="password">Password</wicket:message></label>
                </td>
                <td class="login">
                    <input wicket:id="password" id="password" type="password" name="pswd" value="" size="30" maxlength="16"/>
                </td>
            </tr>
            <tr style="display: table-row;">
                <td class="login">&nbsp;</td>
                <td class="login"><input class="btn" type="submit" name="Login" value="Login" wicket:message="title:loginButtonTitle"/></td>
            </tr>
        </table>
    </form>
</div>
 </wicket:extend>
sardo
  • 2,731
  • 3
  • 19
  • 18