CodeRAD2 - update views

Viewed 29

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:

  • The selected notification details are displayed on a new page.
  • The notification object is updated so isNew flag is changed to false.

What also should happen but doesn't:

  • When going back to the main view, the previously selected notification shouldn't have a badge on it anymore. The badge should automatically be gone with no need to manually refresh the list.

View the project.

1 Answers

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>

Related