如何在 Tapestry 5 中使用带有网格或循环组件的基类或接口?

发布于 2024-07-13 22:12:53 字数 487 浏览 2 评论 0原文

我有一个具体的类 A,它扩展 BaseA 并实现 InterfaceA。 我想使用基类或接口作为循环变量来循环访问 A 列表。 尝试这样的事情:

<t:loop source="listOfA" value="propertyOfTypeBaseA">
    ${propertyOfTypeBaseA.someField}
</t:loop>

给我一个错误“无法找到从类型 A 到 BaseA 的强制转换”。 当我将值设置为 InterfaceA 类型的属性时,也会发生同样的事情。 如果我使用 Object 作为循环变量类型,我可以使循环正常工作,但随后我无法访问具体类或接口上的任何字段。

看起来 Tapestry 应该知道如何从一个对象强制到它实现的接口,但我也尝试从 A 到 BaseA/InterfaceA 进行强制转换,但它仍然给了我这个错误,尽管它实际上在列表中显示了强制转换。

有任何想法吗?

I have a concrete class A that extends BaseA and implements InterfaceA. I want to loop through a list of A using either the base class or interface as the looping variable. Trying something like this:

<t:loop source="listOfA" value="propertyOfTypeBaseA">
    ${propertyOfTypeBaseA.someField}
</t:loop>

gives me an error "Could not find a coercion from type A to BaseA". The same thing happens when I set value to a property of type InterfaceA. I can get the loop to work if I use Object as the looping variable type, but then I can't access any of the fields on the concrete class or the interface.

It seems like Tapestry should know how to coerce from an object to an interface it implements, but I also tried contributing a coercion from A to BaseA/InterfaceA and it still gave me that error, even though it actually showed the coercion in the list.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落花随流水 2024-07-20 22:12:53

如果该界面不在 Tapestry 管理的包中,则该界面将正常工作。 我现在知道“基本”包是 Tapestry 除了页面和组件之外还管理的包。 我将我的基类和接口放入该包中,认为它们不会受到 Tapestry 类加载器巫术的影响。 将它们移出后,我仍然需要为基类提供强制转换,但不需要为接口提供强制转换。

The interface will work if it is not in a package that Tapestry manages. And I now know that the 'base' package is one that Tapestry manages in addition to pages and components. I had put my base class and interface in that package thinking they would be safe from Tapestry's classloader voodoo. After moving them out, I still needed to contribute a coercion for the base class, but not for the interface.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文