0

I'm writing a restaurant management program written by javafx, the program works, there's no error at the console screen, but when I open the adminAccess.fxml file:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.MenuButton?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="557.0" prefWidth="667.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.AdminAccessController">
   <children>
      <AnchorPane layoutX="17.0" layoutY="8.0" minHeight="-Infinity" minWidth="-Infinity" prefHeight="310.0" prefWidth="631.0">
         <children>
            <Label layoutX="117.0" layoutY="250.0" text="Select an inventory to view from the dropdown menu to view its items." />
            <MenuButton layoutY="34.0" mnemonicParsing="false" text="INVENTORIES">
              <items>
                <MenuItem fx:id="foodMenuItem" mnemonicParsing="false" onAction="#foodOnAction" text="Food" />
                <MenuItem fx:id="drinkMenuItem" mnemonicParsing="false" onAction="#drinkOnAction" text="Drink" />
                  <MenuItem fx:id="equipmentMenuItem" mnemonicParsing="false" onAction="#equipmentOnAction" text="Equipment" />
              </items>
            </MenuButton>
            <TableView fx:id="tableView" layoutX="116.0" layoutY="34.0" prefHeight="213.0" prefWidth="500.0">
              <columns>
                  <TableColumn fx:id="itemTypeColumn" prefWidth="75.0" text="ITEM TYPE" />



//ERROR IN ONEDITCOMMIT-The controller 'AdminAccessController' has no event slot 'changeItemIDCellEvent', 'changeItemNameCellEvent','changeItemQuantityCellEvent','changeItemPriceCellEvent'//



                <TableColumn fx:id="idColumn" onEditCommit="#changeItemIDCellEvent" prefWidth="75.0" text="ID" />
                <TableColumn fx:id="nameColumn" onEditCommit="#changeItemNameCellEvent" prefWidth="75.0" text="NAME" />
                  <TableColumn fx:id="quantityColumn" onEditCommit="#changeItemQuantityCellEvent" prefWidth="75.0" text="QUANTITY" />
                  <TableColumn fx:id="priceColumn" onEditCommit="#changeItemPriceCellEvent" prefWidth="75.0" text="PRICE" />
                  <TableColumn fx:id="expirationDateColumn" prefWidth="75.0" text="EXP. DATE" />
              </columns>
            </TableView>
            <Label alignment="CENTER" layoutX="46.0" layoutY="9.0" prefHeight="17.0" prefWidth="540.0" text="ADMINISTRATOR ACCESS" />
            <Label fx:id="errorLabel" layoutX="117.0" layoutY="287.0" prefHeight="17.0" prefWidth="500.0" text="Double click the property of an item or employee you would like to edit to change it." />
            <TextField fx:id="itemName" layoutY="61.0" prefHeight="25.0" prefWidth="105.0" promptText="Name" />
            <TextField fx:id="itemID" layoutY="88.0" prefHeight="25.0" prefWidth="105.0" promptText="Item ID" />
            <TextField fx:id="itemQuantity" layoutY="115.0" prefHeight="25.0" prefWidth="105.0" promptText="Quantity" />
            <TextField fx:id="itemPrice" layoutY="142.0" prefHeight="25.0" prefWidth="105.0" promptText="Price" />
            <Button fx:id="addItemButton" layoutY="196.0" mnemonicParsing="false" onAction="#addItemButtonOnAction" prefHeight="25.0" prefWidth="105.0" text="ADD ITEM" />
            <Button fx:id="deleteItemButton" layoutY="222.0" mnemonicParsing="false" onAction="#deleteItemButtonOnAction" prefHeight="25.0" prefWidth="105.0" text="DELETE ITEM" />
            <Label layoutX="117.0" layoutY="268.0" text="Select an item from an inventory and click the 'DELETE ITEM' button to remove it." />
            <DatePicker fx:id="itemExpirationDate" layoutY="169.0" prefHeight="25.0" prefWidth="105.0" promptText="Exp. Date" />
         </children>
      </AnchorPane>
      <Button fx:id="logOutButton" alignment="CENTER" layoutX="14.0" layoutY="521.0" mnemonicParsing="false" onAction="#logOutButtonOnAction" text="LOG OUT" />
      <Button fx:id="deleteEmployeeButton" layoutX="14.0" layoutY="430.0" mnemonicParsing="false" onAction="#deleteEmployeeButtonOnAction" text="DELETE EMPLOYEE" />
      <Button fx:id="addEmployeeButton" layoutX="14.0" layoutY="403.0" mnemonicParsing="false" onAction="#addEmployeeButtonOnAction" prefHeight="25.0" prefWidth="115.0" text="ADD EMPLOYEE" />
      <TableView fx:id="employeeTableView" layoutX="134.0" layoutY="322.0" prefHeight="133.0" prefWidth="500.0">
        <columns>


//ERROR IN ONEDITCOMMIT-The controller 'AdminAccessController' has no event slot 'changeEmployeeCellEvent','changeEmployeeIDCellEvent','changeEmployeePositionCellEvent'//


          <TableColumn fx:id="employeeNameColumn" onEditCommit="#changeEmployeeNameCellEvent" prefWidth="98.0" text="NAME" />
          <TableColumn fx:id="employeeIDColumn" onEditCommit="#changeEmployeeIDCellEvent" prefWidth="72.66670227050781" text="ID" />
            <TableColumn fx:id="employeePositionColumn" onEditCommit="#changeEmployeePositionCellEvent" prefWidth="82.66668701171875" text="POSITION" />
        </columns>
      </TableView>
      <TextField fx:id="employeeName" layoutX="15.0" layoutY="322.0" prefHeight="25.0" prefWidth="111.0" promptText="Name" />
      <TextField fx:id="employeeID" layoutX="15.0" layoutY="349.0" prefHeight="25.0" prefWidth="111.0" promptText="Employee ID" />
      <TextField fx:id="employeePosition" layoutX="16.0" layoutY="376.0" prefHeight="25.0" prefWidth="111.0" promptText="Position" />
      <Label layoutX="134.0" layoutY="477.0" prefHeight="25.0" prefWidth="474.0" text="Select an employee from the table and click the 'DELETE' button to remove them. " />
      <Label fx:id="messageLabel" layoutX="134.0" layoutY="462.0" text="Enter a new employee's information and click 'ADD EMPLOYEE' to add them to the roster." />
   </children>
</AnchorPane>

And here is a part of the AdminAccessController.java class:

public void changeItemIDCellEvent(TableColumn.CellEditEvent editID) {
        //getting the selected item
        Object itemSelected = tableView.getSelectionModel().getSelectedItem();

        if (itemSelected.getClass().toString().substring(15).equalsIgnoreCase("food")) {
            try {
                int newId = (int) editID.getNewValue();
                //only sets the new ID entered if it is not already in use
                if(!EmployeeAccessController.isDuplicateID(newId)) {
                    int oldId = 0;
                    for (Food food : Food.foodItems) {
                        if(tableView.getSelectionModel().getSelectedItem() == food) {
                            oldId = food.getId();
                            food.setId(newId);
                            break;
                        }
                    }
                    //updating item in data base
                    String sql = "UPDATE Food SET id = ? WHERE id = ?";
                    try (Connection connection = this.connect()) {
                        PreparedStatement statement = connection.prepareStatement(sql);
                        statement.setInt(1, newId);
                        statement.setInt(2,oldId);
                        statement.executeUpdate();
                    } catch (SQLException e) {
                        System.out.println("Không thể update vật tư.");
                    }
                    errorLabel.setText("Sửa vật tư thành công!");
                } else {
                    errorLabel.setText("You entered an ID that is already in use please try again.");
                }
            } catch (NumberFormatException e) {
                errorLabel.setText("You entered an inappropriate value for that field.");
            }
        } else if (itemSelected.getClass().toString().substring(15).equalsIgnoreCase("drink")) {
            try {
                int newId = (int) editID.getNewValue();
                //only sets the new ID entered if it is not already in use
                if(!EmployeeAccessController.isDuplicateID(newId)) {
                    int oldId = 0;
                    for (Drink drink : Drink.drinkItems) {
                        if(tableView.getSelectionModel().getSelectedItem() == drink) {
                            oldId = drink.getId();
                            drink.setId(newId);
                            break;
                        }
                    }
                    //updating item in data base
                    String sql = "UPDATE Drink SET id = ? WHERE id = ?";
                    try (Connection connection = this.connect()) {
                        PreparedStatement statement = connection.prepareStatement(sql);
                        statement.setInt(1, newId);
                        statement.setInt(2,oldId);
                        statement.executeUpdate();
                    } catch (SQLException e) {
                        System.out.println("Could not update item.");
                    }
                    errorLabel.setText("Successfully edited item!");
                } else {
                    errorLabel.setText("You entered an ID that is already in use please try again.");
                }
            } catch (NumberFormatException e) {
                errorLabel.setText("You entered an inappropriate value for that field.");
            }
        } else {
            try {
                int newId = (int) editID.getNewValue();
                //only sets the new ID entered if it is not already in use
                if(!EmployeeAccessController.isDuplicateID(newId)) {
                    int oldId = 0;
                    for (Equipment equipment : Equipment.equipmentItems) {
                        if(tableView.getSelectionModel().getSelectedItem() == equipment) {
                            oldId = equipment.getId();
                            equipment.setId(newId);
                            break;
                        }
                    }
                    //updating item in data base
                    String sql = "UPDATE Equipment SET id = ? WHERE id = ?";
                    try (Connection connection = this.connect()) {
                        PreparedStatement statement = connection.prepareStatement(sql);
                        statement.setInt(1, newId);
                        statement.setInt(2,oldId);
                        statement.executeUpdate();
                    } catch (SQLException e) {
                        System.out.println("Could not update item.");
                    }
                    errorLabel.setText("Successfully edited item!");
                } else {
                    errorLabel.setText("You entered an ID that is already in use please try again.");
                }
            } catch (NumberFormatException e) {
                errorLabel.setText("You entered an inappropriate value for that field.");
            }
        }
    }

I have created many other methods in the AdminAccessController.java class that have similar names to the values on the onEditCommit side that I just mentioned in the adminAccess.fxml class. And there is a warning on such methods: ''TableColumn.CellEditEvent is a raw type. References to generic type TableColumn.CellEditEvent<S,T> should be parameterized'' In the end, the program still runs, but I wonder if this error can be fixed? Or should we just forget about it?

  • 1
    You mention an error, but you reference a warning "TableColumn.CellEditEvent is a raw type.". That is not an error, that is a warning. You can find info about it in the answers to: [List is a raw type. References to generic type List should be parameterized](https://stackoverflow.com/questions/10477570/list-is-a-raw-type-references-to-generic-type-liste-should-be-parameterized) (possible duplicate). Whether you address the warning is up to you. I would suggest, in general, yes fix type warnings, otherwise you lose some type safety (e.g., a compile-time error can become a runtime error). – jewelsea Apr 04 '22 at 21:20
  • Unrelated, but I don't advise running SQL in the event handlers of a controller, see the [eden coding database access guide](https://edencoding.com/connect-javafx-with-sqlite/) for advice on a potential alternative solution. Also, it can be easier to not provide editing and commits in a table, but instead, allow editing of a selected row in a separate form. – jewelsea Apr 04 '22 at 21:21
  • Also don't just write a message to system out when you get an exception, log the full stack trace (preferably using a logging framework, but alternatively e.printStackTrace()) or throw it to a higher level handler. If you only write a message to system out, you lose important information, such as the stacktrace and the cause of the exception (e.g. there are many causes for an SQLException and often you want [the failure code](https://docs.oracle.com/cd/E11882_01/java.112/e16548/apxermsg.htm#JJDBC28962) to have any hope to troubleshoot). – jewelsea Apr 04 '22 at 21:28
  • See the [makery tutorial](https://code.makery.ch/library/javafx-tutorial/), for an example of editing via an external form rather than inline in the table. – jewelsea Apr 04 '22 at 21:31
  • [mcve] please.. mind the __M__! – kleopatra Apr 04 '22 at 21:41

0 Answers0