2016-11-21 62 views
1

WelcomePage.java檢票:org.apache.wicket.markup.MarkupNotFoundException

import org.apache.wicket.markup.html.WebPage; 
import org.apache.wicket.markup.html.basic.Label; 
import org.apache.wicket.model.Model; 

import java.io.Serializable; 
import java.util.ArrayList; 
import org.apache.wicket.markup.html.basic.Label; 
import org.apache.wicket.markup.html.navigation.paging.PagingNavigator; 
import org.apache.wicket.markup.repeater.Item; 
import org.apache.wicket.markup.repeater.data.DataView; 
import org.apache.wicket.markup.repeater.data.ListDataProvider; 
import org.apache.wicket.model.IModel; 
import org.apache.wicket.model.Model; 
import com.ui.*; 



public class WelcomePage extends WebPage{ 

private static final long serialVersionUID = 1L; 

public WelcomePage(){ 

    Contact contact = null; 
    final List<Contact> list = new ArrayList<Contact>(); 

    char character; 

    // a - z 
    for(int i = 97; i < 123; i++){ 
     character = (char) i; 
     contact = new Contact(String.valueOf(character)); 
     list.add(contact); 
    } 

    final DataView<Contact> dataView = 
     new DataView<Contact>("simple", new ListDataProvider<Contact>(list)){ 

      private static final long serialVersionUID = 1L; 

      @Override 
      public void populateItem(final Item<Contact> item){ 
       final Contact user = item.getModelObject(); 
       item.add(new Label("id", user.getId())); 
      } 
     }; 

    dataView.setItemsPerPage(10); 

    add(dataView); 

    add(new PagingNavigator("navigator", dataView)); 
} 

} 

WelcomePage.html

<!DOCTYPE html> 
<html> 

<body> 

<span wicket:id="lbl"> </span> 


<wicket:extend> 

<table cellspacing="0" class="dataview"> 
<tbody> 
    <tr wicket:id="simple"> 
    <td><span wicket:id="id">Test ID</span></td> 
    </tr> 
</tbody> 
</table> 

<div wicket:id="navigator"></div> 

</wicket:extend> 
</body> 
</html> 

上面的代碼是用於顯示數據視圖 - https://cwiki.apache.org/confluence/display/WICKET/A+Simple+DataView+Example

當我執行上面的代碼我收到以下錯誤..

Last cause: Can not determine Markup. Component is not yet connected to a parent. [Page class = com.kaiinos.kriti.ui.WelcomePage, id = 12, render count = 1] 

堆棧跟蹤 - 根源:

org.apache.wicket.markup.MarkupNotFoundException: Can not determine Markup. Component is not yet connected to a parent. [Page class = com.kaiinos.kriti.ui.WelcomePage, id = 12, render count = 1] 
at org.apache.wicket.Component.getMarkup(Component.java:751) 
at org.apache.wicket.Component.internalRender(Component.java:2378) 
at org.apache.wicket.Component.render(Component.java:2341) 
at org.apache.wicket.Page.renderPage(Page.java:1018) 
at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:124) 
at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:236) 
at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:175) 
at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:895) 
at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) 
at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:265) 
at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:222) 
at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:293) 
at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:261) 
at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:203) 
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:284) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) 
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Thread.java:745) 

編輯 - 修改了Java代碼和HTML,但得到相同的error.I只是個初學者。 任何幫助,將不勝感激。Thankyou提前。

+0

檢查您的標記,它是無效的:XML聲明必須是第一位的。 – svenmeier

+0

...並且您正在使用,我們的BasePage是否有其標記? – svenmeier

+1

異常說「WelcomePage」,但你的Java代碼是關於Sub1Page的。另外你的HTML不完整。我需要結束元素,如和'的頁面時,應該使用''。我建議你開始與Wicket的用戶指南:http://wicket.apache.org/learn/#guide –

回答

0

有幾件事情錯了你的代碼提供。如果你想學習如何編寫wicket應用程序(而不是要求明確定義問題的幫助),StackOverflow不適合你。正如@馬丁-G的建議,你可能想看看進入Wicket user guide

至於你當前的代碼:

  • <wicket:extend>定義了一組HTML的,是以<wicket:child>標籤的發生在父組件的標記。這意味着<wicket:extend>之外的任何內容(例如<span wicket:id="lbl"> </span>)都會被忽略。
  • 使用<wicket:extend>表明,有與含有<wicket:child>相關聯的HTML文件中的父組件。您的WelcomePage的父組件是Wicket的WebPage,但它沒有關聯的HTML文件。這意味着您不能在您的WelcomePage中使用<wicket:extend>
  • WelcomePage的構造函數被調用Sub1Page。我猜這是來自你的其他代碼的剩餘物?無論如何,這是無效的。

嘗試重寫HTML爲您WelcomePage喜歡的東西:

<!DOCTYPE html> 
<html xmlns:wicket> 
<body> 

<table cellspacing="0" class="dataview"> 
<tbody> 
    <tr wicket:id="simple"> 
    <td><span wicket:id="id">Test ID</span></td> 
    </tr> 
</tbody> 
</table> 

<div wicket:id="navigator"></div> 
</body> 
</html> 
+0

三江源這麼多的解釋....修改後的HTML代碼的建議,但得到錯誤的 - 最後的原因:無法找到與ID爲「簡單」的成分[Page類= com.kaiinos.kriti.ui.WelcomePage,ID = 0,render count = 1] \t預計:':simple'。 \t找到類似的名字:'' – Spandana

+0

這個異常意味着你的html引用了'wicket:id =「simple」'但是你還沒有添加一個'id'是「simple」的組件。在你的例子中,你正在構建一個id爲「simple」的DataView dataView,並將它添加到頁面中,所以我不確定爲什麼會出現這個錯誤。 你確定你還在將該組件添加到頁面中,並且該id與wicket仍然相同:html中的id? – Buurman