• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / displaytag / 1753

12 Feb 2026 03:17AM UTC coverage: 77.321% (-0.01%) from 77.334%
1753

push

github

web-flow
Merge pull request #1102 from hazendaz/renovate/javax-support-logback-monorepo

Update dependency ch.qos.logback:logback-classic to v1.5.29 (javax-support)

1438 of 2003 branches covered (71.79%)

Branch coverage included in aggregate %.

4034 of 5074 relevant lines covered (79.5%)

0.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.64
/displaytag/src/main/java/org/displaytag/model/HeaderCell.java
1
/*
2
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2002-2026 Fabrizio Giustina, the Displaytag team
6
 */
7
package org.displaytag.model;
8

9
import java.util.Comparator;
10

11
import org.apache.commons.lang3.StringUtils;
12
import org.apache.commons.lang3.builder.ToStringBuilder;
13
import org.apache.commons.lang3.builder.ToStringStyle;
14
import org.displaytag.decorator.DisplaytagColumnDecorator;
15
import org.displaytag.exception.DecoratorException;
16
import org.displaytag.exception.ObjectLookupException;
17
import org.displaytag.properties.SortOrderEnum;
18
import org.displaytag.util.Href;
19
import org.displaytag.util.HtmlAttributeMap;
20
import org.displaytag.util.HtmlTagUtil;
21
import org.displaytag.util.MultipleHtmlAttribute;
22
import org.displaytag.util.TagConstants;
23

24
/**
25
 * DataObject representing the column header. The header cell contains all the properties common to cells in the same
26
 * column.
27
 */
28
public class HeaderCell {
1✔
29

30
    /**
31
     * Map containing the html tag attributes for cells (td).
32
     */
33
    private HtmlAttributeMap htmlAttributes;
34

35
    /**
36
     * Map containing the html tag attributes for header cells (td).
37
     */
38
    private HtmlAttributeMap headerAttributes;
39

40
    /**
41
     * base href for creating dinamic links.
42
     */
43
    private Href href;
44

45
    /**
46
     * param name used in adding a link.
47
     */
48
    private String paramName;
49

50
    /**
51
     * property of the object where to get the param value from.
52
     */
53
    private String paramProperty;
54

55
    /**
56
     * column title.
57
     */
58
    private String title;
59

60
    /** is the column sortable?. */
61
    private boolean sortable;
62

63
    /** Name given to the server when sorting this column. */
64
    private String sortName;
65

66
    /**
67
     * ColumnDecorators.
68
     */
69
    private DisplaytagColumnDecorator[] columnDecorators;
70

71
    /**
72
     * column number.
73
     */
74
    private int columnNumber;
75

76
    /** is the column sorted?. */
77
    private boolean alreadySorted;
78

79
    /**
80
     * property name to look up in the bean.
81
     */
82
    private String beanPropertyName;
83

84
    /** show null values?. */
85
    private boolean showNulls;
86

87
    /**
88
     * max length of cell content.
89
     */
90
    private int maxLength;
91

92
    /**
93
     * max number of words for cell content.
94
     */
95
    private int maxWords;
96

97
    /** group the column?. */
98
    private int group = -1;
1✔
99

100
    /**
101
     * Name of the non-decorated property used during sorting.
102
     */
103
    private String sortPropertyName;
104

105
    /** Should we be attempting to tabulate the totals?. */
106
    private boolean totaled;
107

108
    /**
109
     * Defalt sort order for this column.
110
     */
111
    private SortOrderEnum defaultSortOrder;
112

113
    /**
114
     * The running total for the column.
115
     */
116
    private double total;
117

118
    /**
119
     * Use this comparator for sorting.
120
     */
121
    private Comparator<Object> comparator;
122

123
    /**
124
     * getter for the grouping index.
125
     *
126
     * @return 0 if the column is not grouped or the grouping order
127
     */
128
    public int getGroup() {
129
        return this.group;
1✔
130
    }
131

132
    /**
133
     * setter for the grouping index.
134
     *
135
     * @param groupingOrder
136
     *            int grouping order (int &gt; 0)
137
     */
138
    public void setGroup(final int groupingOrder) {
139
        this.group = groupingOrder;
1✔
140
    }
1✔
141

142
    /**
143
     * getter for the max number of characters to display in the column.
144
     *
145
     * @return int number of characters to display in the column
146
     */
147
    public int getMaxLength() {
148
        return this.maxLength;
1✔
149
    }
150

151
    /**
152
     * setter for the max number of characters to display in the column.
153
     *
154
     * @param numOfChars
155
     *            number of characters to display in the column
156
     */
157
    public void setMaxLength(final int numOfChars) {
158
        this.maxLength = numOfChars;
1✔
159
    }
1✔
160

161
    /**
162
     * getter for the max number of words to display in the column.
163
     *
164
     * @return int number of words to display in the column
165
     */
166
    public int getMaxWords() {
167
        return this.maxWords;
1✔
168
    }
169

170
    /**
171
     * setter for the max number of words to display in the column.
172
     *
173
     * @param numOfWords
174
     *            number of words to display in the column
175
     */
176
    public void setMaxWords(final int numOfWords) {
177
        this.maxWords = numOfWords;
1✔
178
    }
1✔
179

180
    /**
181
     * Should null be displayed?.
182
     *
183
     * @return true null will be displayed in cell content
184
     */
185
    public boolean getShowNulls() {
186
        return this.showNulls;
1✔
187
    }
188

189
    /**
190
     * Enable or disable displaying of null values.
191
     *
192
     * @param outputNulls
193
     *            boolean true if null should be displayed
194
     */
195
    public void setShowNulls(final boolean outputNulls) {
196
        this.showNulls = outputNulls;
1✔
197
    }
1✔
198

199
    /**
200
     * Getter for the name of the property to look up in the bean.
201
     *
202
     * @return String name of the property to look up in the bean
203
     */
204
    public String getBeanPropertyName() {
205
        return this.beanPropertyName;
1✔
206
    }
207

208
    /**
209
     * Setter for the name of the property to look up in the bean.
210
     *
211
     * @param propertyName
212
     *            - name of the property to look up in the bean
213
     */
214
    public void setBeanPropertyName(final String propertyName) {
215
        this.beanPropertyName = propertyName;
1✔
216
    }
1✔
217

218
    /**
219
     * Is the column already sorted?.
220
     *
221
     * @return true if the column already sorted
222
     */
223
    public boolean isAlreadySorted() {
224
        return this.alreadySorted;
1✔
225
    }
226

227
    /**
228
     * Setter for the sorted property (the column is actually sorted).
229
     */
230
    public void setAlreadySorted() {
231
        this.alreadySorted = true;
1✔
232
    }
1✔
233

234
    /**
235
     * Getter for the column number.
236
     *
237
     * @return int column number
238
     */
239
    public int getColumnNumber() {
240
        return this.columnNumber;
1✔
241
    }
242

243
    /**
244
     * Setter for the column number.
245
     *
246
     * @param number
247
     *            - int column number
248
     */
249
    public void setColumnNumber(final int number) {
250
        this.columnNumber = number;
1✔
251
    }
1✔
252

253
    /**
254
     * Returns the columnDecorator object for this column.
255
     *
256
     * @return DisplaytagColumnDecorator
257
     */
258
    public DisplaytagColumnDecorator[] getColumnDecorators() {
259
        return this.columnDecorators != null ? this.columnDecorators : new DisplaytagColumnDecorator[0];
1✔
260
    }
261

262
    /**
263
     * Sets the columnDecorator object for this column.
264
     *
265
     * @param decorator
266
     *            - the DisplaytagColumnDecorator
267
     */
268
    public void setColumnDecorators(final DisplaytagColumnDecorator[] decorator) {
269
        this.columnDecorators = decorator;
1✔
270
    }
1✔
271

272
    /**
273
     * Is the column sortable?.
274
     *
275
     * @return true if the column is sortable
276
     */
277
    public boolean getSortable() {
278
        return this.sortable;
1✔
279
    }
280

281
    /**
282
     * is the column sortable?.
283
     *
284
     * @param isSortable
285
     *            - true if the column can be sorted
286
     */
287
    public void setSortable(final boolean isSortable) {
288
        this.sortable = isSortable;
1✔
289
    }
1✔
290

291
    /**
292
     * Get name given to server for sorting this column.
293
     *
294
     * @return name given to server for sorting this column
295
     */
296
    public String getSortName() {
297
        return this.sortName;
1✔
298
    }
299

300
    /**
301
     * Set name given to server for sorting this column.
302
     *
303
     * @param sortName
304
     *            name given to server for sorting this column
305
     */
306
    public void setSortName(final String sortName) {
307
        this.sortName = sortName;
1✔
308
    }
1✔
309

310
    /**
311
     * Gets the column title.
312
     *
313
     * @return the column title. If no title is specified the capitalized bean property name is returned
314
     */
315
    public String getTitle() {
316
        if (this.title != null) {
1✔
317
            return this.title;
1✔
318
        }
319
        if (this.beanPropertyName != null) {
1✔
320
            return StringUtils.capitalize(this.beanPropertyName);
1✔
321
        }
322

323
        return TagConstants.EMPTY_STRING;
1✔
324
    }
325

326
    /**
327
     * Setter for the column title.
328
     *
329
     * @param value
330
     *            - the column title
331
     */
332
    public void setTitle(final String value) {
333
        this.title = value;
1✔
334
    }
1✔
335

336
    /**
337
     * Returns the HtmlAttributeMap containg all the html attributes for the <strong>td </strong> tags.
338
     *
339
     * @return HtmlAttributeMap with td attributes
340
     */
341
    public HtmlAttributeMap getHtmlAttributes() {
342
        return this.htmlAttributes;
1✔
343
    }
344

345
    /**
346
     * Sets the HtmlAttributeMap containg all the html attributes for the <strong>td </strong> tags.
347
     *
348
     * @param attributes
349
     *            HtmlAttributeMap
350
     */
351
    public void setHtmlAttributes(final HtmlAttributeMap attributes) {
352
        this.htmlAttributes = attributes;
1✔
353
    }
1✔
354

355
    /**
356
     * returns the HtmlAttributeMap containg all the html attributes for the <strong>th </strong> tag.
357
     *
358
     * @return HtmlAttributeMap with th attributes
359
     */
360
    public HtmlAttributeMap getHeaderAttributes() {
361
        return this.headerAttributes;
×
362
    }
363

364
    /**
365
     * Sets the HtmlAttributeMap containg all the html attributes for the <strong>th </strong> tag.
366
     *
367
     * @param attributes
368
     *            HtmlAttributeMap
369
     */
370
    public void setHeaderAttributes(final HtmlAttributeMap attributes) {
371
        this.headerAttributes = attributes;
1✔
372
    }
1✔
373

374
    /**
375
     * Adds a css class to the html "class" attribute.
376
     *
377
     * @param cssClass
378
     *            String
379
     */
380
    public void addHeaderClass(final String cssClass) {
381
        // null safe
382
        if (StringUtils.isBlank(cssClass)) {
1!
383
            return;
×
384
        }
385

386
        // if headerAttributes has not been set, instantiates a new map
387
        if (this.headerAttributes == null) {
1!
388
            this.headerAttributes = new HtmlAttributeMap();
×
389
        }
390

391
        final Object classAttributes = this.headerAttributes.get(TagConstants.ATTRIBUTE_CLASS);
1✔
392

393
        // handle multiple values
394
        if (classAttributes == null) {
1✔
395
            this.headerAttributes.put(TagConstants.ATTRIBUTE_CLASS, new MultipleHtmlAttribute(cssClass));
1✔
396
        } else {
397
            ((MultipleHtmlAttribute) classAttributes).addAttributeValue(cssClass);
1✔
398
        }
399
    }
1✔
400

401
    /**
402
     * return the open tag for a column header (th).
403
     *
404
     * @return String &lt;th&gt; tag with attributes
405
     */
406
    public String getHeaderOpenTag() {
407
        return HtmlTagUtil.createOpenTagString(TagConstants.TAGNAME_COLUMN_HEADER, this.headerAttributes);
1✔
408
    }
409

410
    /**
411
     * return the closing tag for a cell (td).
412
     *
413
     * @return String &lt;/td&gt;
414
     */
415
    public String getCloseTag() {
416
        return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_COLUMN + TagConstants.TAG_CLOSE;
1✔
417
    }
418

419
    /**
420
     * return the closing tag for a column header (th).
421
     *
422
     * @return String &lt;/th&gt;
423
     */
424
    public String getHeaderCloseTag() {
425
        return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_COLUMN_HEADER + TagConstants.TAG_CLOSE;
1✔
426
    }
427

428
    /**
429
     * Setter for the href to be used for dinamic links in cells.
430
     *
431
     * @param baseHref
432
     *            base href for links
433
     */
434
    public void setHref(final Href baseHref) {
435
        this.href = baseHref;
1✔
436
    }
1✔
437

438
    /**
439
     * Getter for the href to be used for dinamic links in cells.
440
     *
441
     * @return Href base href for links
442
     */
443
    public Href getHref() {
444
        return this.href;
1✔
445
    }
446

447
    /**
448
     * Setter for the name of the param to add to links.
449
     *
450
     * @param name
451
     *            name of the param
452
     */
453
    public void setParamName(final String name) {
454
        this.paramName = name;
1✔
455
    }
1✔
456

457
    /**
458
     * Getter for the name of the param to add to links.
459
     *
460
     * @return String name of the param
461
     */
462
    public String getParamName() {
463
        return this.paramName;
1✔
464
    }
465

466
    /**
467
     * Setter for the name of the property to look up in bean to get the param value for links.
468
     *
469
     * @param property
470
     *            name of the property to look up in bean to get the param value for links
471
     */
472
    public void setParamProperty(final String property) {
473
        this.paramProperty = property;
1✔
474
    }
1✔
475

476
    /**
477
     * Getter for the name of the property to look up in bean to get the param value for links.
478
     *
479
     * @return String name of the property to look up in bean to get the param value for links
480
     */
481
    public String getParamProperty() {
482
        return this.paramProperty;
1✔
483
    }
484

485
    /**
486
     * Getter for the name of the property in the bean which will be used for sorting.
487
     *
488
     * @return String name of the property in the bean which will be used for sorting
489
     */
490
    public String getSortProperty() {
491
        return this.sortPropertyName;
1✔
492
    }
493

494
    /**
495
     * Setter for the name of the property in the bean which will be used for sorting.
496
     *
497
     * @param propertyName
498
     *            - name of the property in the bean which will be used for sorting
499
     */
500
    public void setSortProperty(final String propertyName) {
501
        this.sortPropertyName = propertyName;
1✔
502
    }
1✔
503

504
    /**
505
     * Sets the default sort order for this column.
506
     *
507
     * @return default order
508
     */
509
    public SortOrderEnum getDefaultSortOrder() {
510
        return this.defaultSortOrder;
1✔
511
    }
512

513
    /**
514
     * Gets the default sort order for this column.
515
     *
516
     * @param order
517
     *            default order
518
     */
519
    public void setDefaultSortOrder(final SortOrderEnum order) {
520
        this.defaultSortOrder = order;
1✔
521
    }
1✔
522

523
    /**
524
     * To string.
525
     *
526
     * @return the string
527
     *
528
     * @see java.lang.Object#toString()
529
     */
530
    @Override
531
    public String toString() {
532
        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) //
1✔
533
                .append("columnNumber", this.columnNumber) //$NON-NLS-1$
1✔
534
                .append("title", this.title) //$NON-NLS-1$
1✔
535
                .append("beanPropertyName", this.beanPropertyName) //$NON-NLS-1$
1✔
536
                .toString();
1✔
537
    }
538

539
    /**
540
     * Set the column comparator.
541
     *
542
     * @param columnComparator
543
     *            the value
544
     */
545
    public void setComparator(final Comparator<Object> columnComparator) {
546
        this.comparator = columnComparator;
1✔
547
    }
1✔
548

549
    /**
550
     * Get the comparator for sorting this column.
551
     *
552
     * @return the comparator
553
     */
554
    public Comparator<Object> getComparator() {
555
        return this.comparator;
1✔
556
    }
557

558
    /**
559
     * Will we be keeping a total for this column?.
560
     *
561
     * @return true if we are totaling
562
     */
563
    public boolean isTotaled() {
564
        return this.totaled;
1✔
565
    }
566

567
    /**
568
     * Setter for totaled.
569
     *
570
     * @param isTotaled
571
     *            the value
572
     */
573
    public void setTotaled(final boolean isTotaled) {
574
        this.totaled = isTotaled;
1✔
575
    }
1✔
576

577
    /**
578
     * Add the value of this parameter to the column total. The param will be converted to a number via a property
579
     * Converter.
580
     *
581
     * @param value
582
     *            the value
583
     *
584
     * @see Converter#convert(Class, Object)
585
     */
586
    private void addToTotal(final Object value) {
587
        if (value instanceof Number) {
1✔
588
            this.total = this.total + ((Number) value).doubleValue();
1✔
589
        }
590
    }
1✔
591

592
    /**
593
     * Get the current total.
594
     *
595
     * @return the current total.
596
     */
597
    public double getTotal() {
598
        return this.total;
1✔
599
    }
600

601
    /**
602
     * Add a new cell to this column.
603
     *
604
     * @param column
605
     *            the value
606
     */
607
    public void addCell(final Column column) {
608
        // Not actually going to hold a reference to the added cell - we just need access for the totals
609
        if (this.totaled) {
1✔
610
            try {
611
                final Object val = column.getValue(false);
1✔
612
                this.addToTotal(val);
1✔
613
            } catch (ObjectLookupException | DecoratorException e) {
×
614
                throw new RuntimeException(e);
×
615
            }
1✔
616
        }
617
    }
1✔
618

619
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc