Partage
  • Partager sur Facebook
  • Partager sur Twitter

[IHM] - JavaFX / SceneBuilder / Spring

    28 avril 2016 à 16:43:18

    Bonjour tout le monde!

    Mon code Java étant terminé, je voudrais m'atteler à la réalisation d'une toute petite IHM en JavaFX avec SceneBuilder. Ce choix est du à des besoins futurs, je préfère donc commencer à me faire la main sur ces outils.

    La composante problématique dans tout ça est que le projet est un projet Maven, utilisant le Framework Spring. J'ai seulement utilisé le Framework Spring pour récupérer les donnes en BD (autrement dit le Repository).

    Donc mon début d'IHM est fait, cependant, j'arrive pas à initialiser les controlleurs de l'IHM comme les Choicebox, etc...

    L'idée d'IHM (simpliste) :

    Voilà mon code :

    Le Controller :

    public class ConstraintOverviewController {
    
    	XRepository x;
    	ObservableList<X> xList = FXCollections.observableArrayList(x.findAll());
    	ObservableList<String> yList = FXCollections.observableArrayList("FE_1", "FE_2");
    
    	// Reference to the main application.
    	private ConstraintCheckerApplication ConstraintCheckerApplication;
    	@FXML
    	private ChoiceBox<X> xBox;
    	@FXML
    	private ChoiceBox<String> yBox;
    	
    	/**
         * The constructor.
         * The constructor is called before the initialize() method.
         */
        public ConstraintOverviewController() {
        }
    	
        /**
         * Initializes the controller class. This method is automatically called
         * after the fxml file has been loaded.
         */
        @FXML
        private void initialize() {
            // Initialize Choice boxes.
        	xBox.setItems(pxList);
        	yBox.setItems(yList);
        }
        
    programmingDayRepository.findAll();
    
    }
    


    Mon "Main" :

    @SpringBootApplication
    public class TwmuConstraintCheckerApplication extends Application{
    
    	private Stage primaryStage;
    	private BorderPane rootLayout;
    	
    	/**
    	 * Automaticaly call when application start
    	 */
    	@Override
    	public void start(Stage primaryStage) {
    		this.primaryStage = primaryStage;
            this.primaryStage.setTitle("Constraint Checker Tool");
            initRootLayout();
            showPersonOverview();
    	}
    	
    	/**
         * Initializes the root layout.
         */
        public void initRootLayout() {
            try 
            {
                // Load root layout from fxml file.
                FXMLLoader loader = new FXMLLoader();
                loader.setLocation(TwmuConstraintCheckerApplication.class.getResource("view/RootLayout.fxml"));
                rootLayout = (BorderPane) loader.load();
    
                // Show the scene containing the root layout.
                Scene scene = new Scene(rootLayout);
                primaryStage.setScene(scene);
                primaryStage.show();
            } 
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    
        public void showPersonOverview() {
            try 
            {
                FXMLLoader loader = new FXMLLoader();
                loader.setLocation(TwmuConstraintCheckerApplication.class.getResource("view/ConstraintCheckerOverview.fxml"));
                AnchorPane constraintOverview = (AnchorPane) loader.load();
                rootLayout.setCenter(constraintOverview);
            } 
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        
        /**
         * Returns the main stage.
         * @return
         */
        public Stage getPrimaryStage() 
        {
            return primaryStage;
        }
        
    	public static void main(String[] args) {
    		launch(args);
    	}
    	
    }


    Message d'erreur :

    javafx.fxml.LoadException:

    blabla/view/ConstraintCheckerOverview.fxml:17 at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)

    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
    at javafx.fxml.FXMLLoader.load(Unknown Source)
    at com.TwmuConstraintCheckerApplication.showPersonOverview(TwmuConstraintCheckerApplication.java:62)
    at com.TwmuConstraintCheckerApplication.start(TwmuConstraintCheckerApplication.java:28)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    Caused by: java.lang.NullPointerException


    at com.view.ConstraintOverviewController.<init>(ConstraintOverviewController.java:15)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source) at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source)

    at javafx.fxml.FXMLLoader$ValueElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(Unknown Source)
    at javafx.fxml.FXMLLoader$Element.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
    at javafx.fxml.FXMLLoader.processStartElement(Unknown Source) ... 14 more


    Donc je pense que je n'ai pas compris un concept lié à Spring, j'espère que vous pourrez m'éclairer!

    Concrètement je comprend que la liste que je retourne est vide mais pourquoi... je ne sais pas. 

    Un concept inhérent à Spring que je n'ai sans doute pas du tout compris. 

    En vous remerciant par avance,

    Mehdmehd,
     

    -
    Edité par mehdmehd 28 avril 2016 à 16:51:38

    • Partager sur Facebook
    • Partager sur Twitter

    [IHM] - JavaFX / SceneBuilder / Spring

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown