java - 在 Tapestry 中使用自定义创建的组件

标签 java tapestry

我最近开始学习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 文件位于其相应的资源包中。我的问题是,为什么组件文本没有显示?

最佳答案

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

对于组件类 org.example.MyComponent,典型位置是 src/main/resources/org/example/MyComponent.tml,但您必须确保您的 IDE 正在导出 src/main/resources 内的文件。

关于java - 在 Tapestry 中使用自定义创建的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30646146/

相关文章:

java - 使mp3文件连续播放

java - Tapestry 5 仍然需要 .page 或 .jwc 文件吗?

java - OnActionFromStart( Tapestry )

java - 从 Struts 到 Tapestry 的零碎转换 5

java - @Nullable java (android) 的含义

java - 使用 AngularJS 将 URL 中的 RequestParams 传递到 Spring MVC 后端

java - Java包装器作为守护程序

java - 我怎样才能打败类似 RC4 的混淆?

sorting - Tapestry 网格默认排序

java - Tapestry 4 - 省略组件渲染