0

I've got a filtered TableView populate from a ObservableList, when I update an item from ObservableList, item is not update in UI, but if I made a search into table, item appears.

tbcNombre.setCellValueFactory(new PropertyValueFactory<>("nombre"));
tbcApellidos.setCellValueFactory(new PropertyValueFactory<>("apellidos"));
tbcAsistencia.setCellValueFactory(new Callback<CellDataFeatures<Alumno,  Alumno>, ObservableValue<Alumno>>() {
   @Override
   public ObservableValue<Alumno> call(CellDataFeatures<Alumno, Alumno>     features) {
      return new ReadOnlyObjectWrapper(features.getValue());
     }
   });

//datamodel.getAlumnos() returns an observablelist
datosFiltrados = new FilteredList<>(datamodel.getAlumnos());
listaOrdenada = new SortedList<>(datosFiltrados);
listaOrdenada.comparatorProperty().bind(tbvAlumnos.comparatorProperty());
tbvAlumnos.setItems(listaOrdenada);

When I use search function (enter something into textfieldbuscar) tableview is update and I can see update item):

    txtBuscar.textProperty().addListener((observable, oldValue, newValue) -> {
        datosFiltrados.setPredicate(alumnoAux -> {
            boolean aux = false;

            if (StringUtils.isEmpty(newValue)) {
                aux = true;
            } else if (alumnoAux.toString().toLowerCase().contains(newValue.toLowerCase())) {
                aux = true;
            }

            return aux;
        });

        if (datosFiltrados.size() == 0) {
            btnDetalles.setDisable(true);
            btnBorrar.setDisable(true);
        } else {
            btnDetalles.setDisable(false);
            btnBorrar.setDisable(false);
        }
    });
Marcos
  • 4,827
  • 3
  • 20
  • 28
  • Just ref this solution http://stackoverflow.com/questions/11065140/javafx-2-1-tableview-refresh-items – Reegan Miranda Jan 30 '15 at 05:39
  • tableView.getColumns().get(0).setVisible(false); tableView.getColumns().get(0).setVisible(true); – Reegan Miranda Jan 30 '15 at 05:56
  • Thanks @reegan-miranda for your answer, but I use last JDK preview and method setVisible() not exists for getColumns().get(x). – Marcos Jan 30 '15 at 11:49
  • If things are set up correctly, you do not need hacks such as hiding and showing columns, or rebuilding the table items. Can you post your model class (`Alumno`)? And can you specify exactly what you are updating? – James_D Jan 30 '15 at 13:12
  • Alumno's POJO contains only String members like name, surname... but all members are string no stringproperties because I use Hibernate which not support officially data types binding from JavaFX. Update happends after user double click a row, a window appears with row data, user can change data and after that, update data in observablelist. The problem is that UI is not update and row appears with same data. But I have a search textfield where user enter some text and table is filtered, when user do that, row appears with update data. – Marcos Jan 30 '15 at 15:06
  • If you don't use observable properties, there is no way for the table to know the values have changed. Use observable properties with "property access" in Hibernate (i.e. annotate the `get` methods, not the fields). See [this blog](http://svanimpe.be/blog/properties-jpa.html). – James_D Jan 30 '15 at 17:48

0 Answers0