当从容器触发操作时如何更新组件内的区域

发布于 2024-10-09 10:30:04 字数 1783 浏览 3 评论 0原文

我有一个页面:Test.tml,其中包含一个选择和一个组件:

       <t:zone t:id="zone1" t:clientId="zone1">
        <form t:id="form" id="form" method="post">
            <p>
                <select t:type="select" t:id="simpleSelect" t:clientId="simpleSelect" t:value="simpleSelect" t:model="selectList" t:zone="zone1" />
            </p>
        </form>
  <div t:type="SimpleTestComponent" t:id="simpleTestComponent" ></div>
</t:zone>

在 Test.java 中,我捕获了事件:

@OnEvent(value = EventConstants.VALUE_CHANGED, component = "simpleSelect")
public Object changeOnSelect(String value) {
    return zone1.getBody();
}

它很好地更新了 zone1

我有一个组件,其中也包含一个选择和一个要更新的区域;组件选择的内容取决于容器选择表单值,因此我还需要更新组件的内容。如果我的组件内没有区域,它可以很好地工作,但事实并非如此。

在 SimpleTestComponent.tml 中,我有 :

   <form t:id="form" id="form" method="post">
        <p>
            <select t:type="select" t:id="nameSelect" t:clientId="nameSelect" t:value="nameSelected" t:model="nameList" t:zone="zoneComponent"/>
        </p>
    </form>
     <t:zone t:id="zoneComponent" t:clientId="zoneComponent">
    <p>${nameSelected}</p></t:zone>

并在 SimpleTestComponent.java => 中

@OnEvent(value = EventConstants.VALUE_CHANGED, component = "nameSelect")
public Object valueChanged() {
    return zoneComponentId.getBody();
}

我捕获了选择更改,并更新了值。

我现在想要的是当选择从 Test.tml 更改时也能够更新 SimpleTestComponent 的内容。如果我在 zone1 中包含 simpleTestComponent,则会出现关于 simpleTestComponent 内区域的错误,并且当我触发 Test.java 中的 valueChanged 事件时返回 MultiZoneUpdate,其中包含 zone1 和组件区域(我在区域组件上放置了公共 getter) ,我也有一个错误,那么解决方案是什么......?

我不确定是否完全清楚,谢谢您的阅读。 :)

I have a page : Test.tml which contain a select and a component :

       <t:zone t:id="zone1" t:clientId="zone1">
        <form t:id="form" id="form" method="post">
            <p>
                <select t:type="select" t:id="simpleSelect" t:clientId="simpleSelect" t:value="simpleSelect" t:model="selectList" t:zone="zone1" />
            </p>
        </form>
  <div t:type="SimpleTestComponent" t:id="simpleTestComponent" ></div>
</t:zone>

In Test.java, i catch the event :

@OnEvent(value = EventConstants.VALUE_CHANGED, component = "simpleSelect")
public Object changeOnSelect(String value) {
    return zone1.getBody();
}

which well update zone1

And i have a component which also contain a select and a zone to update; the content of the component select depend of the container select form value, so i need to update also the content of component. If i don't have a zone inside my component it works well, but it's not the case.

inside SimpleTestComponent.tml, i have :

   <form t:id="form" id="form" method="post">
        <p>
            <select t:type="select" t:id="nameSelect" t:clientId="nameSelect" t:value="nameSelected" t:model="nameList" t:zone="zoneComponent"/>
        </p>
    </form>
     <t:zone t:id="zoneComponent" t:clientId="zoneComponent">
    <p>${nameSelected}</p></t:zone>

and in SimpleTestComponent.java =>

@OnEvent(value = EventConstants.VALUE_CHANGED, component = "nameSelect")
public Object valueChanged() {
    return zoneComponentId.getBody();
}

I catch the select change, and i update the value.

What i want now is to be able to also update the content of SimpleTestComponent when the select is changed from Test.tml. If i include simpleTestComponent inside zone1, i have an error, about the zone inside simpleTestComponent, and i return a MultiZoneUpdate when i trigger the valueChanged event in Test.java, with zone1 and the component zone (i put a public getter on zone component), i also have an error, so what's the solution ... ?

I'm not sure to be perfectly clear, thx for reading. :)

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

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

发布评论

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

评论(1

塔塔猫 2024-10-16 10:30:04

您需要使嵌入区域 (zoneComponent) 可用于包含组件:

public class SimpleTestComponent
{
    public Zone getZoneComponent()
    {
        return zoneComponentId;
    }
}

然后从测试类中的事件处理程序返回该区域:

public class Test
{
    @InjectComponent
    private SimpleTestComponent simpleTestComponent;

    @OnEvent(value = EventConstants.VALUE_CHANGED, component = "simpleSelect")
    public Object changeOnSelect(String value)
    {
        return simpleTestComponent.getZoneComponent();
    }
}

You will need to make your embedded zone (zoneComponent) available to containing components:

public class SimpleTestComponent
{
    public Zone getZoneComponent()
    {
        return zoneComponentId;
    }
}

and then return that zone from your event handler in your Test class:

public class Test
{
    @InjectComponent
    private SimpleTestComponent simpleTestComponent;

    @OnEvent(value = EventConstants.VALUE_CHANGED, component = "simpleSelect")
    public Object changeOnSelect(String value)
    {
        return simpleTestComponent.getZoneComponent();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文