GWT Datagrid : Inserting widget into the column

落爺英雄遲暮 提交于 2019-12-12 01:18:08

问题


I am trying to insert a textbox inside a datagrid column. I know I could have gone with TextCell or EditTextCell but for some reason I went with TextBox.

I went with the following approach

Cell<String> cell = new AbstractCell<String>()
    {

        @Override
        public void render( com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb )
        {
            FlowPanel fp = new FlowPanel();
            TextBox tb = new TextBox();
            tb.setText( value );
            fp.add( tb );
            sb.appendEscaped( fp.getElement().getString() );
        }
    };
    // Address.
    Column<ContactInfo, String> addressColumn = new Column<ContactInfo, String>( cell )
    {
        @Override
        public String getValue( ContactInfo object )
        {
            return object.getAddress();
        }
    };

The problem I encountered here is that I am getting the following in the UI instead of textbox

<div><input class="gwt-TextBox" type="text"></div>

But when I replaced

sb.appendEscaped( fp.getElement().getString() );

with

sb.appendHtmlConstant( fp.getElement().getInnerHTML() );

I am getting the textbox, But the value is not populating.

Can anyone explain this behaviour. How can I populate the value?


回答1:


Don't create a FlowPanel and a TextBox widget. Instead:

sb.appendHtmlConstant("<input class=\"gwt-TextBox\" type=\"text\" value=\"" + myValue + "\"></input>");

where myValue is what you want to see in a textbox.




回答2:


Why don't you use TextInputCell http://www.gwtproject.org/javadoc/latest/com/google/gwt/cell/client/TextInputCell.html ?



来源:https://stackoverflow.com/questions/12401923/gwt-datagrid-inserting-widget-into-the-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!