SeeMoreGain
SeeMoreGain

Reputation: 1273

i18n in DataFX, JavaFX application getting LoadException: No resources specified

I am new to DataFX (and using DataFx8) and struggling to get localisation working. My main class is as shown:

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        //set language
        ViewConfiguration viewConfig = new ViewConfiguration();
        Locale locale = new Locale("en","EN");
        viewConfig.setResources(ResourceBundle.getBundle(UIConstants.LANGUAGE_BUNDLE_PREFIX, locale));

        Flow applicationRootFlow = new Flow(HomeController.class, viewConfig);
        FlowHandler applicationRootFlowHandler = applicationRootFlow.createHandler();

        StackPane root = applicationRootFlowHandler.start(new DefaultFlowContainer());
        primaryStage.setScene(new Scene(root, UIConstants.APPLICATION_WIDTH, UIConstants.APPLICATION_HEIGHT));
        primaryStage.setTitle(UIConstants.APPLICATION_TITLE);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

I have traced the code through, and the debug shows the Flow has loaded the resource successfully (see attached image). enter image description here

The resource has the required index, but the fxml is not loading the string, instead crashing with Caused by:... javafx.fxml.LoadException: No resources specified. /C:/.../Home.fxml:22

The line in the fxml is:

<Label fx:id="languageLabel" text="%displayLanguage" />

The resource bundle is:

applicationTitle=Service222222
displayLanguage=English

So is there something I am missing? Can I no longer do translation straight from fxml file due to different loading model of datafx (controller specifies fxml file)?

Upvotes: 2

Views: 760

Answers (1)

SeeMoreGain
SeeMoreGain

Reputation: 1273

For others who come across this: This is due to a bug when calling createHandler() method on the Flow. The current DataFx implementation ignores the ViewConfiguration object that is associated with the Flow and will always create new configurations (resources is always null) when returning the FlowHandler object.

As a workaround, avoid calling createHandler() to get the FlowHandler object. Instead, create it manually by calling the FlowHandler constructor that takes in the view configurations as a parameter.

applicationRootFlowHandler = new FlowHandler(applicationRootFlow, new ViewFlowContext(), viewConfig);

Upvotes: 4

Related Questions