Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8096424

Impossible to clear the fx:id attribute - causes tools (e.g. NetBeans 8.0) to generate bad controller code.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • None
    • 8
    • javafx
    • Windows 7 64-bit
      Scene Builder 2.0 b9

      The default is to have no fx:id attribute at all. I just tested by adding a single button to a new document and saving.. this is the result:

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

      <?import java.lang.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
      <children><Button layoutX="231.33837890625" layoutY="38.0" mnemonicParsing="false" text="Button" />
      </children></AnchorPane>

      But as soon as you enter anything in the fx:id field then you get the fx:id attribute and you can't get rid of it..even by hitting the little button at the side of the edit box and selecting "Reset to default".
      <?xml version="1.0" encoding="UTF-8"?>

      <?import java.lang.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane fx:id="" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
      <children><Button layoutX="231.33837890625" layoutY="38.0" mnemonicParsing="false" text="Button" />
      </children></AnchorPane>


      With Scene Builder 1.1 the results is different. We start with:
      <?xml version="1.0" encoding="UTF-8"?>

      <?import java.lang.*?>
      <?import java.util.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>
      <?import javafx.scene.paint.*?>

      <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
        <children>
          <Button layoutX="256.0" layoutY="102.0" mnemonicParsing="false" text="Button" />
        </children>
      </AnchorPane>

      and if you edit the field and then clear it you get the same thing.. no fx:id attribute at all.

      NetBeans is expecting to see a valid string for the fx:id and will generate code in the controller (via the Make Controller action) using whatever string it finds. So it generates a line of code that looks like this:

      @FXML
      AnchorPane ;

      with no identifier.

      I have also filed this as NB bug #240005

            eleponn Eric Le Ponner
            swpalmer Scott Palmer
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: