Issue 82: HeaderRenderer and HeaderEditor should work like other Renderers and Editors.
Status:  Fixed
Owner:
extremec...@gmail.com
Closed:  Feb 2008
Reported by extremec...@gmail.com, Feb 20, 2008
On the wiki you mention that the HeaderEditor and the CellEditor work
exactly the same.
But I've been facing some problems when adding a checkbox on the header,
just like the suggestion.
Apparently, the code is not being inserted in the same place on the header
as it is for the cells.
For example:

Adding a checkbox to a cell, would result on something like:
<td>
    <input type="checkbox" id="id" value="value" />
</td>

On the other hand, when doing that to the header, the result is:
<th <input type="checkbox" id="id" value="value" />>
which, of course, is prone to errors.

Ok, so we did a terrible work-around and added a closing bracket before the
input code when generating it through the editor.
That was a solution for desperate times. But now I'm looking back and
refactoring things and came to face those two classes mentioned on the subject.

On HTMLCellRenderer, the render method goes as follows:

    public Object render(Object item, int rowcount) {
        HtmlBuilder html = new HtmlBuilder();
        html.td(2);
        html.width(getColumn().getWidth());
        html.style(getStyle());
        html.styleClass(getStyleClass());
        html.close();

        String property = getColumn().getProperty();
        Object value = getCellEditor().getValue(item, property, rowcount);
        if (value != null) {
            html.append(value.toString());
        }

        html.tdEnd();

        return html.toString();
    }

But, on HTMLHeaderRenderer, things are not the same. Check it out:

    public Object render() {
        HtmlBuilder html = new HtmlBuilder();

        String element =
getCoreContext().getPreference(HtmlConstants.HEADER_RENDERER_ELEMENT);
        if (element.equalsIgnoreCase("td")) {
            html.td(2);
        } else {
            html.th(2);
        }
       
        html.width(getColumn().getWidth());
        html.style(getStyle());
        html.styleClass(getStyleClass());

        html.append(getHeaderEditor().getValue());

        if (element.equalsIgnoreCase("td")) {
            html.tdEnd();
        } else {
            html.thEnd();
        }

        return html.toString();
    }

The major difference, in my opinion, is where the
html.append(getHeaderEditor().getValue()); is invoked. That's probably the
place where I'd expect for some changes.
Feb 23, 2008
#1 extremec...@gmail.com
Moved the header editor to be an inner div. This makes working with the header editor
to be consistent with the other editors.
Feb 23, 2008
#2 extremec...@gmail.com
(No comment was entered for this change.)
Status: Fixed