Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top