Table resizing problem

Hi,

I need to verify if this is an actual bug and if there is a possible workarund. I have found that the Table component does not adjust itself when one of its child components in a row changes its height at runtime. In addition, I haven’t found a way to manually tell the Table to refresh itself to fix it. Here’s a simple case to show the problem:


Table tbl = new Table();
tbl.setSelectable(false);
tbl.setPageLength(0);
tbl.addContainerProperty("NAME", String.class, "", "Name", null, null);
tbl.setEditable(true);

tbl.setTableFieldFactory(new TableFieldFactory () {
	public Field createField(Container container, Object itemId, Object propertyId, Component uiContext) {
		final TextField tf = new TextField();
		tf.setData(itemId);
		tf.setImmediate(true);
		tf.addListener(new ValueChangeListener() {
			@Override
			public void valueChange(ValueChangeEvent event) {
				tf.setHeight("100px");
			}
		});
		return tf;
	}
});

With this example you will see that when you trigger a ValueChangeEvent by entering text into the TextField, the field will expand its height, the row will adjust accordingly, but the actual Table wrapper will stay the same and scrollbars will be added. If you add a
tbl.requestRepaintAll()
in the event listener it will do nothing. I have tried many things here and none of them worked.
My actual use case is that I have a Custom Field component consisting of a list of TextFields that maps to a String. The component has buttons for the user to add/remove TextFields. When a button is pressed in the component the described behavior occurs. I also have a button in the screen to add more rows to the Table. When you click it then the Table is refreshed and the rows are displayed as they should.

So, is there a way to 'fix this or is there a workaround I can use (CSS, extending Table)?

Thanks!

Hello Luis,

this is not a bug, but (perhaps) a missing feature.
The table is rendering all rows in the same height (Otherwise the lazy loading and scrollbar position/length is not possible)

So neither having rows with different heights is supposed to work, even less changing row heights for single rows once the data is loaded…

But would be nice if that would be possible :wink:

André

Thanks André for the quick response!

The thing is that if you allow to add rows to the Table at runtime, when the Table redraws itself to add the new row (Item) then everything is shown correctly, meaning having rows with different heights. Anyway, the question would be how can I override this behavior. I have also seen another thing I don’t understand: in my custom field component I have added an event to notify when the size of the component changes. When I add a listener, no matter what I do inside the listener it doesn’t get pushed to the client until the next user action. It seems like the changes get cached in the server and not get send to the client. Only the custom component is refreshed, everything outside the component (or the Table perhaps) is ignored.

Any ideas?

Did you use the setImmediate(true) for the component(s) ?

André

Yes! I have tried all possible combinations of setImmediate(true) in all the levels, from the component up to all containers, and none has made a difference. It seems like all the code executed after the custom component repaints itself is not send to the client until the next call. With the debug console I can see that no matter what I do on the server only the component gets refreshed.

Hi Luis,
concerning your first issue, with table height not being recalculated, I was struggling with the same issue, and found out two solutions:
First, rather desperate, was to recreate whole table - remove existing component from layout and create new one with modified rows. It worked but I imagine it isn’t very efficient.
About second solution, just about minute ago, while roaming through VScrollTable sources, I found out that if I set Table’s experimental field ‘alwaysRecalculateColumnWidths’ to true, it works as well. Javadoc says it is experimental, thus no setter and you have to extend the table to enable it (field is protected). It also says that with this client will recalculate column widths, but seems to me that table height is some how dependent and recalculated as well.

Maciej.

That’s interesting about the widths perhaps fixing the height, too.

We’ve had issues with a Table that may contain only 1 row that will render correctly 90% of the time, but ever now and again, it will show only a sliver of that row. We’ve not been able to figure it out, and reloading the page doesn’t even fix it.