0

I am using a Grid to display books information. Those books a historical novels and they are sorted by the year in which action is occurred. My first column in the grid is this year. Book object has this year as integer where positive numbers are AD and negative are BC. I am rendering this column with following class:

    public class ActionYearRenderer extends ComponentRenderer<Div, Book> {

    private Integer lastYear = Integer.MIN_VALUE;
    
    public void reset() {
        this.lastYear = Integer.MIN_VALUE;
    }
    
    @Override
    public Div createComponent(Book item) {
        Integer actionYear = item.getActionYear();
        Div result = new Div();
        if(!Objects.equals(actionYear, lastYear)) {            
            lastYear = actionYear;
            if(actionYear < -10000) {
                result.setText("Prehistoric times");
            } else if (actionYear >= 0) {
                result.setText("year " + actionYear.toString());
            } else {
                result.setText("year " + Integer.toString(Math.abs(actionYear)) + " B.C.E.");
            }
        }
        result.getStyle().set("word-wrap", "normal");
        return result;
    }   
}

I need to display a year only once for the all books referring to a single year. It is working almost as I wanted it to do. It displays everything correctly at the beginning, but I also have ItemDetailsRenderer, which opens book annotation and review. When details are closed, action year disappears from the grid. I presume, that the item is being re-rendered and it is causing this behavior. How can I preserve the content of this cell?

Gary Greenberg
  • 1,084
  • 8
  • 14

0 Answers0