开发者

How to update a zone inside a component when action is triggered from the container

开发者 https://www.devze.com 2023-02-01 12:27 出处:网络
I have a page : Test.tml which contain a select and a component : <t:zone t:id=\"zone1\" t:clientId=\"zone1\">

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 er开发者_开发技巧ror, 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. :)


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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消