2015-06-04 41 views
1

我最近開始學習Tapestry框架。我正在關注如何創建自定義組件並在代碼中使用它。出於某種原因,組件中的文本沒有顯示(我只看到hello world文本)。這裏是的.java和TML文件:在掛毯中使用自定義創建的組件

public class Index 
{ 
    public Index() { 

    } 

    public String getHello() 
    { 
     return "Hello world!"; 
    } 
} 

指數TML:

<html xmlns:t="http://tapestry.apache.org/schema/ 
tapestry_5_3.xsd"> 
<head> 
<title>Tapestry 5 Book</title> 
</head> 
<body> 
<t:MyComponent/> 

<h1> ${hello} </h1> 


</body> 
</html> 

MyComponent.java

public class MyComponent { 

    public String getStuff() 
    { 
     return "Random stuff"; 
    } 
} 

MyComponent.tml

<span> ${stuff} </span> 

我也想說.java文件在他們的對應文件中修復程序包(main/java中的頁面和組件)和.tml文件位於其相應的資源包中。我的問題是,爲什麼組件文本沒有顯示?

回答

0

對我來說一切看起來都不錯,所以它確實只是一個絕對驗證MyComponent.tml位於正確位置並且在運行時在類路徑中可見的情況。例如,這可能是IDE配置的一個問題。

對於組件類org.example.MyComponent,典型的位置是src/main/resources/org/example/MyComponent.tml,但是您必須確保IDE在src/main/resources中導出文件。

+0

那麼這個文件夾裏我可以找到MyComponent.tml文件 src \ main \ resources \ com \ example \ tutorial \ components – Dvorog

+0

我也在MyComponent構造函數中放了一個System.out.println行來測試構造函數被調用。構造函數未被調用。 – Dvorog

+0

下一步是在啓動時發佈控制檯輸出;它列出了Tapestry在啓動時識別的所有頁面和組件。 –