Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7830705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:21:59+00:00 2026-06-02T11:21:59+00:00

I am trying to create a CellTable that has a column with some text

  • 0

I am trying to create a CellTable that has a column with some text and a checkbox, which will be used as a select all checkbox (see the drawing below, “cb” is checkbox). Currently I am using an class derived from Header and overriding it’s render method to output the text and a checkbox. I am overriding onBrowserEvent() however it is only giving me onChange events, which would work fine except that the checkbox doesn’t function correctly. Does anyone have any ideas on this?

+-------+------------+
| col 1 | Select All |
|       |     cb     | 
+-------+------------+
| row 1 |     cb     |
+-------+------------+

The issues I’m having with the checkbox is that when it’s not checked, you have to click it twice for the checkmark to appear (at least on Chrome), even though it’s “checked” property is true the first time. One click unchecks it correctly.

Here is some code:

Setup the CellTable columns:

/** Setup the table's columns. */
private void setupTableColumns() {
    // Add the first column:
    TextColumn<MyObject> column1 = new TextColumn<MyObject>() {
        @Override
        public String getValue(final MyObject object) {
            return object.getColumn1Text();
        }
    };
    table.addColumn(macColumn, SafeHtmlUtils.fromSafeConstant("Column1"));

    // the checkbox column for selecting the lease
    Column<MyObject, Boolean> checkColumn = new Column<MyObject, Boolean>(
            new CheckboxCell(true, false)) {
        @Override
        public Boolean getValue(final MyObject object) {
            return selectionModel.isSelected(object);
        }
    };

    SelectAllHeader selectAll = new SelectAllHeader();
    selectAll.setSelectAllHandler(new SelectHandler());
    table.addColumn(checkColumn, selectAll);
}

My Select All Header:

public static class SelectAllHeader extends Header<Boolean> {
    private final String checkboxID = "selectAllCheckbox";
    private ISelectAllHandler handler = null;

    @Override
    public void render(final Context context, final SafeHtmlBuilder sb) {
        String html = "<div>Select All<div><input type=\"checkbox\" id=\"" + checkboxID + "\"/>";

        sb.appendHtmlConstant(html);
    }

    private final Boolean allSelected;

    public SelectAllHeader() {
        super(new CheckboxCell());

        allSelected = false;
    }

    @Override
    public Boolean getValue() {
        Element checkboxElem = DOM.getElementById(checkboxID);

        return checkboxElem.getPropertyBoolean("checked");

    }

    @Override
    public void onBrowserEvent(final Context context, final Element element, final NativeEvent event) {
        Event evt = Event.as(event);
        int eventType = evt.getTypeInt();

        super.onBrowserEvent(context, element, event);

        switch (eventType) {
            case Event.ONCHANGE:
                handler.onSelectAllClicked(getValue());
                event.preventDefault();
                break;

            default:
                break;
        }

    }


    public void setSelectAllHandler(final ISelectAllHandler handler) {
        this.handler = handler;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T11:22:00+00:00Added an answer on June 2, 2026 at 11:22 am

    It looks like you’re rendering a non-checked checkbox whenever you render the header, which could be wiping out the selection state whenever the celltable re-renders.

    Try storing the checked state and rendering the checkbox with the state. It looks like you’re half way there with allSelected, you’re just not using it.

    EDIT Here is a working implementation I’ve just written for Zanata (see SearchResultsView.java). The HasValue interface is implemented so that value change events can be handled in a standard way. I have not overridden the render method, if you want to do so make sure you use getValue() to determine whether you render a checked or an unchecked checkbox. The selection/de-selection logic is handled in the associated presenter class (see SearchResultsPresenter.java).

    private class CheckboxHeader extends Header<Boolean> implements HasValue<Boolean> {
    
       private boolean checked;
       private HandlerManager handlerManager;
    
       public CheckboxHeader()
       {
          //TODO consider custom cell with text
          super(new CheckboxCell());
          checked = false;
       }
    
       // This method is invoked to pass the value to the CheckboxCell's render method
       @Override
       public Boolean getValue()
       {
          return checked;
       }
    
       @Override
       public void onBrowserEvent(Context context, Element elem, NativeEvent nativeEvent)
       {
          int eventType = Event.as(nativeEvent).getTypeInt();
          if (eventType == Event.ONCHANGE)
          {
             nativeEvent.preventDefault();
             //use value setter to easily fire change event to handlers
             setValue(!checked, true);
          }
       }
    
       @Override
       public HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler)
       {
          return ensureHandlerManager().addHandler(ValueChangeEvent.getType(), handler);
       }
    
       @Override
       public void fireEvent(GwtEvent<?> event)
       {
          ensureHandlerManager().fireEvent(event);
       }
    
       @Override
       public void setValue(Boolean value)
       {
          checked = value;
       }
    
       @Override
       public void setValue(Boolean value, boolean fireEvents)
       {
          checked = value;
          if (fireEvents)
          {
             ValueChangeEvent.fire(this, value);
          }
       }
    
       private HandlerManager ensureHandlerManager()
       {
          if (handlerManager == null)
          {
             handlerManager = new HandlerManager(this);
          }
          return handlerManager;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a macro which can be used for print debug messages when
I'm trying to create a button that will simply link back to the context
I'm trying to create a Temp Table that has a key field that auto
I am trying create an application which will clone the GIT repository to the
I'm trying create a regex that verifies an xml entity name is valid (see
I'm currently trying create a service that will return results of a OLAP cube
I am trying create a trending system that displays which keywords are trending by
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.