I'm going out on a limb here, and hoping that someone has used IT Mill Toolkit before:
I have a Table with a bunch of Items inside. I edit one of them – how do I get the Table to refresh and re-render itself? I've tried with requestRepaint(), requestRepaintAll() on both the table, and the Layout that contains the Table, but I can't get it to refresh itself. When I reload the page, or scroll back and forth (so that the Item goes from view and comes back into view), the Item has been updated.
Is there a way to programmatically get the Table to refresh its current view?
Doesn't the item container implement this feature? Say that you use a IndexedContainer in your Table. AFAIK the IndexedContainer notices when you change the content, and it in turn sends a notice to everything using it as a datasource (= table). So a normal table should pick this up.
Edit- checked this:
IndexedContainer implements Property.ValueChangeNotifier
Table implements ValueChangeListener which runs a requestRepaint().
In other words, your container also has to implement the notifier so that the automatic repaint can be called.
Related
I have a NatTable component with the following layers:
ViewportLayer
SelectionLayer
RowHideShowLayer
ColumnGroupExpandCollapseLayer
ColumnHideShowLayer
DataLayer
I need to show/hide a specific column, when a checkbox selection changes. In order to that, I use the #doCommand() method provided by the NatTable component:
if(selection) {
nattable.doCommand(new ColumnShowCommand(nattable, COLUMN_INDEX));
} else {
nattable.doCommand(new ColumnHideCommand(nattable, COLUMN_INDEX+1));
}
Everything works just fine, excepting the case when ALL the items in the table are selected, and the ColumnHideCommand is executed. On this specific scenario, the whole table content disappears (Screenshot). If there is no selection in the table, or not all the elements are selected, then everything works just fine.
Please let me know if you have any idea what's going on there or if you experienced this kind of issues before. My experience with NatTables is quite limited, so please let me know if you need any additional information. Thank you!
This is a feature of the SelectionLayer to support multi column hide operations based on the column selection. A ColumnHideCommand get consumed and instead a MultiColumnHideCommand is created and executed based on the fully selected columns. The code in charge is located in SelectionLayer#handleColumnHideCommand(ColumnHideCommand). The method is protected, so if you don't need that feature because you only support column hide/show programmatically and not via UI performed by a user, you can override the method to simply perform a super.doCommand(command); without the check for selections.
i have a form with an option group, textfields, comboboxes and so on. the form is bound to a certain dataset of a table. every time i navigate through the table datasets the form datasource is set.
now the important part: iam curious why the valuechange listener of the optiongroup is triggered through setItemDatasource (if the value of the option group changes)? Is it a vaadin bug? How can i solve this? Thanks a lot.
I am currently using FileWriter to write data into .txt tile.
Once I double click the row in the table, it links to another jFrame.
I wanted to set a button at the particular jFrame so that it is able to delete the row in the table. How can I perform the action?
Use the MVC (Model-View-Controller) paradigm.
Have a controller class, maybe containing the main method.
That holds the views (JFrame) and the data models (i.e. a DefaultTableModel).
That table model is passed to the table, which actually is also a listener to changes of the table model.
On button press let the button tell the controller that a row should be deleted.
This is done on the table model, and change events are fired. Automatically when using a DefaultTableModel. Or do it manually when using an AbstractTableModel.
MVC is not necessarily more direct, but there are not calls from one component to another components littered through the sources. It decouples things.
This can be done by adding a New button. Go into the codding of the button and add a simple sql statement saying to drop a row from the table And the another statement to show the table again by Select * from tablename;
I want to refresh the JTable data by clicking a button.
The problem is that the old data in the JTable can't be removed and the new data are just added into the table. I tried below ways to remove the old data but none of them works.
1. table.setModel(new DefaultTableModel());
2. ((DefaultTableModel)table.getModel()).setRowCount(0);
3. ((DefaultTableModel)table.getModel()).fireTableDataChanged();
4. ((DefaultTableModel)table.getModel()).getDataVector().removeAllElements();
5. table.repaint();
6. model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Having a refresh button for a JTable is very suspect. It makes me think you aren't correctly adding data as JTables should refresh everytime data is added or removed.
I would verify a couple of things when using a DefaultTableModel:
Make sure to only add data using addRow
Data should only be inserted using insertRow
Remove data using removeRow
Never modify the internal vectors directly. It won't cause events to fire and you're stuck with a refresh button. I don't know why they even expose it. The JavaDocs should at least specifically warn against this.
If all else fails, fire up a debugger and see what happens.
More of your code might be appropriate here. Hard to tell exactly where you're calling these methods and the order. If you change the model and then call fireTableDataChanged() it should work....assuming you've updated the right TableModel. There is a good Java tutorial for using tables: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
Had the same issue myself, but my solution was different. After checking just about everything, I checked the contents of the table via the console, and found that the contents were indeed being updated. However, the update was not being reflected on the table which was visible on the screen.
In fact, this code:
model = (DefaultTableModel)table.getModel();
while(model.getRowCount() > 0) {
model.removeRow(0);
}
Did not only remove the rows, but also removed the table.
My solution was to remove the table from the form and then re-add it, whenever the table data was changed.
Seemed in my case there was nothing wrong with my coding to generate the table but that the layout manager didn't like overwriting or updating a component the area where I wanted to put it already had something in there.
Something weird going on methinks but at the end of the day this worked for me.
scenario: i have a model anel opened in whci i have a commandlink which opens another model to search for data adn the data is poplated in a datatable with a link in one of the column. On click of the link i need to fetch the row data an populate the value inside the parent model panel .
Problem: i am not able to get the row data form the child panel using a4j:action params and also the when the child panel is cosed the parent panel is also getting closed.
Can any one please help me solving this issue . i know this is a known problem but if any one has a work around for it please let me know.
Use <f:setPropertyActionListener> in the link in the table. Thus you set the current entity in a managed bean
in the modal panel simply output the value of the currently selected item. For example #{yourBean.current.name} (you have set current on the previous step)
The link better be <a4j:commandLink> (or button), so that you can reRender the modal panel in order to obtain the new data