How do i pass an Entity from selected row in rowtemplate to AbstractEntityListProvider

Viewed 35

I have fetched data and populated in view using provider and rowTemplate.

Upon clicking the row, I want to pass the entity to another provider which will trigger getRequest with the values of the entity.

How do I go about passing this selected entity to the provider?

1 Answers

You can do this by adding a lead component button to your row, and bind it to an action, so that it triggers an action which will be caught by your controller. Your controller will contain the logic that does something with this event, such as passing the entity to a provider.

I've created a github repo with a small example of this here: https://github.com/shannah/coderad-entitylist-sample

The key parts. The view:

<define-category name="ROW_CLICKED" />
...
<entityList layout-constraint="center"
                provider="com.example.myapp.providers.SampleListProvider.class"

    >
        <row-template>
            <y rad-leadComponent="ClickMeButton">
                <radLabel tag="UserProfile.name"/>
                <button uiid="ClickMeButton" hidden="true">
                        <bind-action category="ROW_CLICKED"/>
                </button>
            </y>

        </row-template>
    </entityList>

Notice the define-category tag, which defines a ROW_CLICKED action category, which we will use in our button.

Next, inside the <row-template> we wrap the row in a container. I use a <y> container, but you can use any type. The key is the rad-leadComponent="ClickMeButton" which will pipe all events for the container to the child component with uiid "ClickMeButton", which will be our button.

Then the Button has a bind-action with our ROW_CLICKED category, so that it will fire events up to our controller.

In the controller:

protected void initControllerActions() {
        super.initControllerActions();
        addAction(StartPage.ROW_CLICKED, evt-> {
            evt.consume();
            UserProfile profile = (UserProfile)evt.getEntity();
            Dialog.show("Hello", "You clicked " + profile.getName(), "OK", null);
        });
    }

So you can see that we can get the entity from the event. Here I just show a dialog with some entity details, but you could alternatively pass the entity to another provider.

Related