带有注入消息的组件范围服务

发布于 2024-12-01 09:40:07 字数 617 浏览 7 评论 0原文

我知道挂毯服务/资源有一些特殊之处,例如请求、消息等,它们仅在组件渲染的上下文中可用。

我需要创建一个大量使用消息存储并且仅在组件渲染范围内可用的服务。

有人可以解释如何正确配置此服务,以便我可以在每次使用它时使用适当的 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 技术交流群。

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

发布评论

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

评论(1

农村范ル 2024-12-08 09:40:07

事实证明,最好的解决方案是将消息对象作为参数传递到另一个服务的方法中:

@Inject @Property private MyService myService;
@Inject @Property private Messages messages;

<t:output value="myService.getSomething(messages)" />

turns out the best solution was to pass the messages object into another service's methods as an argument:

@Inject @Property private MyService myService;
@Inject @Property private Messages messages;

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