• 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

48.89
/displaytag/src/main/java/org/displaytag/decorator/CheckboxTableDecorator.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.decorator;
8

9
import java.io.IOException;
10
import java.util.ArrayList;
11
import java.util.Arrays;
12
import java.util.List;
13
import java.util.Objects;
14

15
import javax.servlet.jsp.JspWriter;
16
import javax.servlet.jsp.PageContext;
17

18
import org.displaytag.model.TableModel;
19

20
/**
21
 * A table decorator which adds checkboxes for selectable rows.
22
 */
23
public class CheckboxTableDecorator extends TableDecorator {
1✔
24

25
    /** The id. */
26
    private String id = "id";
1✔
27

28
    /** The checked ids. */
29
    private List<String> checkedIds;
30

31
    /** The field name. */
32
    private String fieldName = "_chk";
1✔
33

34
    /**
35
     * Setter for <code>id</code>.
36
     *
37
     * @param id
38
     *            The id to set.
39
     */
40
    public void setId(final String id) {
41
        this.id = id;
×
42
    }
×
43

44
    /**
45
     * Setter for <code>fieldName</code>.
46
     *
47
     * @param fieldName
48
     *            The fieldName to set.
49
     */
50
    public void setFieldName(final String fieldName) {
51
        this.fieldName = fieldName;
×
52
    }
×
53

54
    /**
55
     * Inits the.
56
     *
57
     * @param pageContext
58
     *            the page context
59
     * @param decorated
60
     *            the decorated
61
     * @param tableModel
62
     *            the table model
63
     *
64
     * @see org.displaytag.decorator.Decorator#init(javax.servlet.jsp.PageContext, java.lang.Object,
65
     *      org.displaytag.model.TableModel)
66
     */
67
    @Override
68
    public void init(final PageContext pageContext, final Object decorated, final TableModel tableModel) {
69
        super.init(pageContext, decorated, tableModel);
1✔
70
        final String[] params = pageContext.getRequest().getParameterValues(this.fieldName);
1✔
71
        this.checkedIds = params != null ? new ArrayList<>(Arrays.asList(params)) : new ArrayList<>(0);
1!
72
    }
1✔
73

74
    /**
75
     * Finish.
76
     *
77
     * @see org.displaytag.decorator.TableDecorator#finish()
78
     */
79
    @Override
80
    public void finish() {
81

82
        if (!this.checkedIds.isEmpty()) {
1!
83
            final JspWriter writer = this.getPageContext().getOut();
×
84
            for (final String name : this.checkedIds) {
×
85
                final StringBuilder buffer = new StringBuilder();
×
86
                buffer.append("<input type=\"hidden\" name=\"");
×
87
                buffer.append(this.fieldName);
×
88
                buffer.append("\" value=\"");
×
89
                buffer.append(name);
×
90
                buffer.append("\">");
×
91
                try {
92
                    writer.write(buffer.toString());
×
93
                } catch (final IOException e) {
×
94
                    // should never happen
95
                }
×
96
            }
×
97
        }
98

99
        super.finish();
1✔
100

101
    }
1✔
102

103
    /**
104
     * Gets the checkbox.
105
     *
106
     * @return the checkbox
107
     */
108
    public String getCheckbox() {
109

110
        final String evaluatedId = Objects.toString(this.evaluate(this.id));
1✔
111

112
        final boolean checked = this.checkedIds.contains(evaluatedId);
1✔
113

114
        final StringBuilder buffer = new StringBuilder();
1✔
115
        buffer.append("<input type=\"checkbox\" name=\"_chk\" value=\"");
1✔
116
        buffer.append(evaluatedId);
1✔
117
        buffer.append("\"");
1✔
118
        if (checked) {
1!
119
            this.checkedIds.remove(evaluatedId);
×
120
            buffer.append(" checked=\"checked\"");
×
121
        }
122
        buffer.append("/>");
1✔
123

124
        return buffer.toString();
1✔
125
    }
126

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

© 2026 Coveralls, Inc