Search code examples
javawicketwicket-1.5

How to refresh label after changing color in wicket


I use Wicket 1.5

When i change color it is really changed on the page only after refreshing using F5. How to refresh it in backend?

I use this lines for changing color: dateDescription.add(AttributeModifier.replace("style", "color:red;")); add(dateDescription);

UPDATE #1 Now i use AJAX but still have to refresh page for changing color. Could you tell me what i did wrong?

    // in page class
    public class FilterUpdateBehavior extends AjaxFormComponentUpdatingBehavior {
        public FilterUpdateBehavior(String event) {
            super(event);
        }

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            RefreshResult result = getResult(target);
            if (result.getStatus() == RefreshResultStatus.DATE_NOT_SET) {
                dateIntervalFilterPanel.setAlarmDateStatus(true);
            } else {
                dateIntervalFilterPanel.setAlarmDateStatus(false);
            }
        }
    }
    
    
    // in date panel class
    dateDescription.add(new AttributeModifier("style", new AbstractReadOnlyModel<String>() {
                private static final long serialVersionUID = 1L;

                @Override
                public String getObject() {
                    String cssClass = null;
                    if (isAlarmDateStatus()) {
                        cssClass = "color:red;";
                    } else {
                        cssClass = "color:black;";
                    }
                    return cssClass;
                }
            }));
    add(dateDescription);

UPDATE #2

    public RefreshResult getResults(AjaxRequestTarget target) {
        // ... somewhere here additional logic of getting particulate RefreshResult
        target.add(table);
        target.add(paging);
        target.add(loadingPanel);
        return new RefreshResult(resultType);
    }

UPDATE #3 FINAL (IT HELPED ME) I miss this code line when i change isAlarmDateStatus, now it works fine. Thanks to Andrea!

    target.add(dateDescription);

Solution

  • your code line looks right but you must use AJAX to reflect your changes without reloading the entire page. Unfortunately Wicket 1.5 is really outdated and there are few resources online to provide you an example of AJAX support. You might try to look into the old 1.5 AJAX examples code here:

    https://github.com/apache/wicket/tree/build/wicket-1.5.17/wicket-examples/src/main/java/org/apache/wicket/examples/ajax/builtin