V
V
Vitaly Voskobovich2015-01-09 14:21:49
JavaFX
Vitaly Voskobovich, 2015-01-09 14:21:49

JavaFX: How to open a detailed view window when clicking on a row in a table?

When you click on a row in the table, you need to show a window filled with the model that I have chosen.
I catch the event, here is the handler

/**
     * Событие выбора строки
     * Срабатывает когда пользователь выбирает строку в таблице продуктов.
     *
     * @param item - выбранная модел продукта
     */
    private void selectRowAction(Order item) {
        this.updateTable();
        AnchorPane orderFormView = OrderFormController.getView();
        BreadCrumbs.setView(orderFormView);
    }

OrderFormController.getView:
/**
     * Геттер представления карточки товара
     * @return
     */
    public static final AnchorPane getView() {
        try {
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(Object.class.getResource("/views/OrderForm.fxml"));
            return loader.load();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

Now this code shows the desired form to the user, but does not fill it with data.
The problem is that the view file is the leader. After it is loaded, the controller is already loaded, and the initialize () method is already loaded in it, and handlers are already hung there and the content of the view changes.
The problem is that I don't know how to tell the initialize() method "Load me THIS model into the view".
Who knows how to solve and where to dig?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
volna80, 2015-01-15
@volna80

Get the controller from the loader, bring it to the real one to the class and call the method that will load the necessary data before

Object controller = loader.getController();
((MyController) controller).loadOrder(order)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question