【问题标题】:Using custom created components in tapestry在挂毯中使用自定义创建的组件
【发布时间】:2015-06-04 14:09:35
【问题描述】:

我最近开始学习 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>

我的组件.java

public class MyComponent {

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

我的组件.tml

<span> ${stuff} </span>

我还想说,.java 文件在它们对应的包中(main/java 中的页面和组件...),而 .tml 文件在它们对应的资源包中。我的问题是,为什么组件文本没有显示?

【问题讨论】:

    标签: java tapestry


    【解决方案1】:

    在我看来一切正常,所以这实际上只是绝对验证 MyComponent.tml 是否在正确的位置,并且在运行时在类路径中可见的情况。例如,这可能是 IDE 配置的问题。

    对于组件类 org.example.MyComponent,典型的地方是 src/main/resources/org/example/MyComponent.tml,但是你必须确保你的 IDE 是在 src/main/resources 里面导出文件。

    【讨论】:

    • 这是我可以找到 MyComponent.tml 文件 src\main\resources\com\example\tutorial\components 的文件夹
    • 我还在 MyComponent 构造函数中放置了 System.out.println 行来测试构造函数是否被调用。构造函数没有被调用。
    • 下一步是在启动时发布控制台输出;它列出了 Tapestry 在启动时识别的所有页面和组件。
    • 我通过将以下代码:tapestry.apache.org/schema/tapestry_5_3.xsd"> 放在一行中解决了这个问题 :)。
    猜你喜欢
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-19
    • 2020-08-24
    • 2018-10-09
    • 1970-01-01
    相关资源
    最近更新 更多