带有注入消息的组件范围服务
我知道挂毯服务/资源有一些特殊之处,例如请求、消息等,它们仅在组件渲染的上下文中可用。
我需要创建一个大量使用消息存储并且仅在组件渲染范围内可用的服务。
有人可以解释如何正确配置此服务,以便我可以在每次使用它时使用适当的 Messages 对象创建它吗?
例如(我知道这行不通):
public class MyServiceImpl
{
@Inject private Messages messages;
@Override
public String getSomeMessage(Object someParameter)
{
...
}
}
然后我可以像这样使用它:
public class MyComponent
{
@Inject
@Parameter
private MyService myService;
}
tml:
<p>${myService.getSomeMessage('someParameter')}</p>
谢谢,保罗。
I am aware that there is something special about tapestry services/resources such as Request, Messages etc which are only available in the context of a component render.
I need to create a service which makes heavy use of the messages store and is available only in the scope of a component render.
Can someone explain how I can configure this service correctly so that I can create it with the appropriated Messages object each time it is used?
eg (i know this wouldn't work):
public class MyServiceImpl
{
@Inject private Messages messages;
@Override
public String getSomeMessage(Object someParameter)
{
...
}
}
and then i could use it like so:
public class MyComponent
{
@Inject
@Parameter
private MyService myService;
}
tml:
<p>${myService.getSomeMessage('someParameter')}</p>
Thanks, Paul.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,最好的解决方案是将消息对象作为参数传递到另一个服务的方法中:
turns out the best solution was to pass the messages object into another service's methods as an argument: