1

既存の Web アプリケーションを Wicket 1.4 から 1.5 に移植しています。アプリには、ベース ページの子である 2 つのテンプレート ページがあります。テンプレートにはセキュアおよび非セキュアという名前が付けられ、認証済みユーザーと認証されていないユーザーのページを定義します。アプリ内のすべてのページは、これらのテンプレートから継承されます。Wicket 1.4 では、このセットアップは問題なく正常に機能しました。

Wicket 1.5 に移植した後、次のエラーが表示されます。

[HtmlHeaderContainer] で ID 'PageTitle' のコンポーネントが見つかりません

「PageTitle」は Wicket ラベルであり、ベース ページのページ タイトルを動的に構築するために使用され<head>、ベース ページ マークアップのタグに配置されます。私が発見したのは、<head>マークアップが 2 回レンダリングされていることです。そのため、Wicket が PageTitle を 1 回作成してから再度作成しようとするため、エラーが発生したと推測されます (これ<head>はベース ページのマークアップでのみ定義されます)。

手っ取り早い修正方法は、PageTitle をテンプレートに移動することです (重複コード)。この問題を解決するより良い方法はありますか?

私の説明が十分に明確であることを願っていますが、必要に応じてコード例を提供できます。

4

2 に答える 2

0

リクエストに応じて、ここにコードサンプルがあります。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 など、削除):

<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>

}

アプリケーション ページ、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);
}

...

}

ログイン.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>
于 2012-06-29T09:36:58.940 に答える