I have an editable Table in a Form in which one of the columns/properties is a TextArea showing up to 3 lines.
It appears to work fine when I’m editing the form. The textarea appear, has scrollbars and allows me to enter values as expected. The same is true for a TextArea that appears directly in the Form (not in a table).
However, when that Form is put into read-only mode, and the table is removed from edit mode, the textareas do not wrap or present scrollbars when in the Table, but it does work as expected when that TextArea is directly in the Form (that is, it shows multiple lines and adds scrollbars if the contents are bigger than can fit).
Is there a way to have the readonly textarea not show just one line when in a Table? It would be nice if it worked the same in a Form as in a Table so that when my TextArea is set to show 3 lines (setRows(2)), it would allow that space in the Table, and/or add scrollbars to allow the additional data to be viewed from within the table.
Is this possible? Again, in edit mode, all is good, but in read-only mode, the TextArea in the Form shows multiple lines and adds scrollbars for bigger content, while the TextArea in a Table shows only a single line without scrollbars.
I’m not sure what you code is like, but if I understood correctly, you have a table, where one column is a TextArea in editable mode. But what is the column property type?
If the column type is String, it will show as a string in the table in non-editable mode, and TextArea (or whatever you return in the field factory) in the editable mode. In Table, string columns are not wrapped.
If the column type is TextArea, it will be a TextArea also in non-editable mode. And you can edit it.
You could also use a GeneratedColumn to display the TextArea in non-editable mode.
Notice that setting read-only for a Table does not make its contained components read-only in non-editable mode. This is because the “value” of the table is its selection, not its content, so only the selection is read-only.
You are right that I create the columns as type String since the data I put in a TextField or TextArea is a string.
And my table’s field factory does indeed return TextArea components.
By the way, this is exactly the same setup for the TextArea that’s directly in the Form. My get/set BeanItem uses String (not TextArea as the type), but in the field factory for the form, I return a TextArea. It works as expected, showing the String in a TextArea for edit, and in scrollable area when in readonly mode.
For a Table I need to do something different? Should I instead create an Item in which the properties are TextAreas? I never thought of an Item as containing widgets rather than data elements. If I do, then I will get/set TextAreas, and presumably get/set my actual String data into them. Is that the idea?
I want the TextArea in the Table to behave like the TextArea in a Form so that it shows a scrollable read-only field when it’s not in edit mode. Thanks for any clarifications before I give it a try…
The use of an Item containing a TextField and two TextAreas to represent the columns in my editable Table is new to me, but it does seem to resolve the issue I was having with the TextArea not scrolling in read-only mode, but with other issues now.
When doing this, there’s apparently no longer a need for a Table field factory as these are created directly into the Item. Despite my configuring the field factory, it’s no longer being called, presumably because the contents are already fields.
In fact, it’s now easier to track all of the fields I put in the Table (I am tracking them for commit/discard/validate/isValid/isModified code as the Form doesn’t do the fields inside the Table automatically), and I no longer see the constant re-creation of fields like I did with the field factory.
But, my code that used to check if any of the Fields inside the Table have been modified no longer works. That is, every field, despite the fact when I view it in the debugger shows the new value I entered into that field, field.isModified() returns false.
What might cause that? How have the values stored inside the TextField and TextAreas inside my Table been changed, but not showing return true for field.isModified()? The fields I create for the Table are marked as setWriteThrough(false) because I want to control the commit/discard in the containing Form.
The other solution is to use GeneratedColumn to display the value as a TextArea also in the read-only mode. Then, you need to either regenerate the column when switching between editable/non-editable mode to set the TextAreas to read-only mode in the non-editable mode.
I can try the other approach, but I initially took the approach of putting a TextArea into the Item that drives the table.
What I found is that even though the field (TextArea) inside the table is being updated, the call to Field.setValue() ends up calling AbstractField.setValue(Object newValue, boolean repaintIsNotNeeded):
// Changes the value
setInternalValue(newValue);
modified = dataSource != null;
Is there a reason why the changed value is not recorded in ‘modified’ unless there’s a data source? There’s code above that exits early if setValue() is called with the current value (no change really), so is there a reason why the field’s modified flag is only valid when a data source is used?
Perhaps I need to revert and use the generated column. It seems like the way I’ve done it works fine except for this small matter that even though the value of the field is changing, it’s not being remembered in the field object so I can’t tell if the field was changed – which I’m trying to detect to bring up a discard warning option when the user navigates away without clicking Save/Cancel buttons.
Maybe this change resolved things. It seems to work now that I use a simple data source instead of just setting the value directly. Not sure why I’d need to do this more convoluted way, but it now at least will tell me the field has been modified when setValue() is called with a new value.
This basically creates a TextField (as well as TextAreas) and converts the value into an ObjectProperty to be the field’s data source. Not sure if this is correct or a bad thing, but it seems to work. The commented-out code that used setValue() worked as well, except that it never recorded being modified.
I guess this makes sense since if I call ‘discard’ it need to refresh from the original data source. Hope this is the right way to do what I want, which is have a Table in edit mode containing a TextArea that will also show a readonly textarea (with scrollbars) when the Table is removed from edit mode.