Supernova
Supernova

Reputation: 33

CodeRAD2 - update views

I'm trying to update a view after some data change with no luck.

So in the main view, a list of notifications are displayed. New notifications have a red badge to the right. When I select a notification from the list in the main view the following happens:

What also should happen but doesn't:

View the project.

Upvotes: 1

Views: 39

Answers (1)

steve hannah
steve hannah

Reputation: 4716

I found an issue that could affect updating of list views that are off-screen at the time of the model update. I have published this in maven central as version 2.0.4. It should be available shortly.

In addition, you'll need to make a small change to your project.

In your NotificationView.xml you have a script tag:

<script>
        notification.getComponent().setBadgeText(context.getEntity().isNew() ? " " : "");

</script>

This appears to be what you were relying on to handle the dynamic badge. Unfortunately a script tag only runs once at the time when the component is created, so this won't be run again when the model updates, as you appear to be expecting.

The easiest solution is to use a the bind-component.badgeText attribute on the radLabel instead, as this "binds" the badgeText value to the resultof the expression.

E.g.

<radLabel
                layout-constraint="center"
                tag="Notification.title"
                rad-var="notification"
                component.uiid="MyH2"
                bind-component.badgeText='java:context.getEntity().isNew() ? " " : ""'
                component.badgeUIID="MyBadge"
        />

Alternatively, you could use the tag approach, except add a listener that is called on update. E.g.

<script>
        notification.addUpdateListener(()-> {
            notification.getComponent().setBadgeText(context.getEntity().isNew() ? " " : "");
        });

</script>

Upvotes: 1

Related Questions