GWT CellTable, disable ButtonCell when clicked

I am new to GWT, but so far I have been making pretty quick progress.

I have a table of cells, most of which are read-only data returned from RPC.

I have two columns in a cell table that the user can interact with. One of them is TextInputCell, one is ButtonCell.

When the user clicks the ButtonCell button, I want to send a value to TextInputCell for this line in RPC.

It all works for me.

The part that I can’t work with is that when I press the button (ButtonCell) I want to disable the button on this line until the RPC returns and then turns it back on. I also want to clear the text in the input cell for this line when the RPC returns.

I cannot figure out how to get the handles for the actual ButtonCell object that was clicked, or TextInputCell for the monkey with them.

Any help was appreciated.

Bk

+5
source share
2 answers

The problem is that there was no object for the button. Your ButtonCell creates HTML code that displays the buttons — each button in the entire column was written by the same button, but there is no java object associated with them.

To disable a button directly, you first need to create a handle. You can do this by specifying the id in the html that the ButtonCell creates, and then get the element by id from the DOM.

, , . , - ( , CellTable Grid). , , .

Cell, - . , . !

PS: ( ), , onBrowserEvent Element, - .

+4

, .

check this code

package com.ex7.client;

import com.google.gwt.cell.client.ButtonCell;
import com.google.gwt.cell.client.ValueUpdater;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.NativeEvent;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class CWButton extends ButtonCell {
    private int row = -1;
    private String alternativevalue;
    private String exTitle = "";

    private String value;
    private String title = "";

    public CWButton( ) {
        super();

    }

    @Override
    public void render(com.google.gwt.cell.client.Cell.Context context,
            String src, SafeHtmlBuilder sb) {

        if (row == -1) {
            sb.appendHtmlConstant("<button   title='" + title + "'  >" +value+"</button>");
            return;
        }

        if (row != context.getIndex()) {

            sb.appendHtmlConstant("<Button   disabled='disabled'   title='" + title + "'  >"+ value+"</button>");
        } else {
            sb.appendHtmlConstant("<button    title='" + exTitle + "' >"+ alternativevalue+"</button>");
        }

    }

    @Override
    public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context,
            Element parent, String value, NativeEvent event,
            ValueUpdater<String> valueUpdater) {

        if (row == -1 || row == context.getIndex()) {
            super.onBrowserEvent(context, parent, value, event, valueUpdater);
            return;
        }

    }

    public void setTitle(String title) {

        this.title = title;
    }

    public int getRow() {
        return row;
    }

    public String getExTitle() {
        return exTitle;
    }

    public void setExTitle(String exTitle) {
        this.exTitle = exTitle;
    }

    public void setRow(int row) {
        this.row = row;
    }

    public String getAlternativeValue() {
        return alternativevalue;
    }

    public void setAlternativeValue(String alternativeValue) {
        this.alternativevalue = alternativeValue;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

}
+4
source

All Articles