简体   繁体   中英

Tapestry event dynamic components

I want to implement an eventhandler for a component, which is dynamically generated. That means I have a Table , whichs source is bound to a custom TableModel (which implements an interface JsonGenerator , with which the json data can be generated). In this TableModel , I add a few custom components, which fire an event ( valueChanged ) when their state changes. Those components have ids (1 to 4). However, I can't just add a method similiar to this:

void onValueChangedFrom1 ()

as there are times when no component with the id 1 exists. I'd get the following exception when trying anway:

Method de.[...].onValueChangedFrom1() references component id '1' which does not exist.

I can't modify the custom TableModel , the JsonGenerator nor the other custom components.

It might be interesting to know that the values of the custom components can be accessed via the Request service of tapestry like that:

request.getParameter("1");

But how can I add an event handler when this value changes? Is this even possible in Tapestry?

You can add the 1-4 as context on the event and capture it in your event handler. Your event handler needs to be component agnostic though, meaning you need an event handler for all, ie

public void onValueChanged(@RequestParameter("newValue") Object newValue, int context) {
    ...
}

Then on each of your custom components add the context to the event, you did not show how you are currently generating the event so I am not able to tell you what to update.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM