GWT CellTable,单击时禁用按钮cell

GWT CellTable,单击时禁用按钮cell,gwt,gwt-celltable,Gwt,Gwt Celltable,我是GWT的新手,但到目前为止,我的进步相当快 我有一个单元格表,其中大部分是从RPC返回的只读数据 我在单元格表中有两列,用户可以与之交互。一个是TextInputCell,一个是ButtonCell 当用户单击ButtonCell时,我想将该行的TextInputCell中的值发送到RPC 我有所有这些工作 我无法开始工作的部分是,当单击按钮(ButtonCell)时,我想禁用该行中的按钮,直到RPC返回,然后重新启用它。我还想在RPC返回时清除该行输入单元格中的文本 我不知道如何获得被单击

我是GWT的新手,但到目前为止,我的进步相当快

我有一个单元格表,其中大部分是从RPC返回的只读数据

我在单元格表中有两列,用户可以与之交互。一个是TextInputCell,一个是ButtonCell

当用户单击ButtonCell时,我想将该行的TextInputCell中的值发送到RPC

我有所有这些工作

我无法开始工作的部分是,当单击按钮(ButtonCell)时,我想禁用该行中的按钮,直到RPC返回,然后重新启用它。我还想在RPC返回时清除该行输入单元格中的文本

我不知道如何获得被单击的实际ButtonCell对象的句柄,或者如何使用TextInputCell来处理它们

谢谢你的帮助


bq

问题是,单击的按钮没有对象。ButtonCell创建HTML来呈现按钮-整个列中的每个按钮都是由同一个按钮单元编写的,但是没有与它们关联的java对象

要直接禁用按钮,您必须首先为其创建一个句柄。可以通过在ButtonCell创建的html中呈现id,然后从DOM中按id获取元素来实现这一点

在类似的情况下,我所做的只是在状态发生变化时重新呈现整个表。它不需要那么长时间,而且您不需要存储任何引用(这就是您使用CellTable而不是Grid的全部原因)。当您知道应该禁用按钮时,只需将其渲染为禁用即可

这两个建议都要求您对单元对象进行子类化,以便可以进行一些自定义渲染。这不是很难,但是把你的脑袋绕在操作顺序上可能会让人困惑。祝你好运


PS:如果您只想禁用按钮(而不是清空文本字段),我认为onBrowserEvent为您提供了单击的
元素
的句柄-您可以使用它来禁用它。

我已经解决了这个问题,但最终我解决了它

检查此代码

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;
    }

}
package com.ex7.client;
导入com.google.gwt.cell.client.ButtonCell;
导入com.google.gwt.cell.client.ValueUpdater;
导入com.google.gwt.dom.client.Element;
导入com.google.gwt.dom.client.NativeEvent;
导入com.google.gwt.safehtml.shared.SafeHtmlBuilder;
公共类CWButton扩展ButtonCell{
私有整数行=-1;
私有字符串可选值;
私有字符串exTitle=“”;
私有字符串值;
私有字符串title=“”;
公用按钮(){
超级();
}
@凌驾
public void render(com.google.gwt.cell.client.cell.Context),
字符串src,SafeHtmlBuilder sb){
如果(行==-1){
sb.附加HtmlConstant(“+value+”);
返回;
}
if(row!=context.getIndex()){
sb.附加HtmlConstant(“+value+”);
}否则{
sb.附加HtmlConstant(“+alternativevalue+”);
}
}
@凌驾
public void onBrowserEvent(com.google.gwt.cell.client.cell.Context,
元素父级、字符串值、NativeEvent事件、,
ValueUpdater(ValueUpdater){
if(行==-1 | |行==context.getIndex()){
onBrowserEvent(上下文、父级、值、事件、值更新程序);
返回;
}
}
公共无效集合标题(字符串标题){
this.title=标题;
}
public int getRow(){
返回行;
}
公共字符串getExTitle(){
返回exTitle;
}
公共void setExTitle(字符串exTitle){
this.exTitle=exTitle;
}
公共无效集合行(整数行){
this.row=行;
}
公共字符串getAlternativeValue(){
返回可选值;
}
public void setAlternativeValue(字符串alternativeValue){
this.alternativevalue=alternativevalue;
}
公共字符串getValue(){
返回值;
}
公共void设置值(字符串值){
这个值=值;
}
}