JavaFX application with multiple fxml files - model-view-controller

I have been through java docs, java online courses/presentations on youtube and threads on stackoverflow, but never found an easy and great method to interact between different views on javafx applications. And most of the times examples have been showing only one view at the time.
Researches I have done so far is that a fxml file needs a controller to be hooked with, and if you have more fxml files, the proper way would be to get a controller to each of them.
What I still do not understand is the Abstract Parent class. Why is it created an instance of that in the javafx fxml application at the beginning on start method? Do I need to instantiate it again when I am trying to load a new fxml file? Same goes to the FXMLLoader. What exactly is fx:root construct? Other researches I have observed are that you do not necessarily need multiple stages or scenes to load a new fxml file.
What I am trying to achieve is an lightweight and simple looking chat application in javafx. Right now I am working on the Client application and planning to apply 3 fxml files: login, chat and submit new user. I do not know wether I should create new stage and scene, only new scene or just replacing the fxml file, one at the time, inside the current stage & scene? Basically I want login to point me to chat screen, new user to create acc screen and both of them to point me back to login screen.
The part I am struggling with is the FXMLLoad part and who is parent and children to who or are all of them parent? And how to organize the files. I have uploaded two images to show you how I am thinking and what I want to approach. Is it really possible to load a new fxml at time to current stage & scene, based on ActionEvent? If yes, how can i approach that?
I hope I made it clear.
javafxarchitecture of my application
loginscreen

Related

Extract HTML Helpers from Razor views

Situation
We are rebuilding a web application (winforms), from the ground up. The old application will keep running, when the new one is released. This means that the new application needs to talk to an old database, I can't change anything there. The new application will be build with .NET Core 2.0 MVC.
The old application uses a custom translation database table, based on a language-id and translation-id. Very straighforward.
Problem
The old application made a database call for each translation, over and over again. Because the new application needs to reuse this table, i'd rather have a smarter system. Because of the amount of translations, I don't want to get all data on each page request. I also don't want to make a database-call for each translation.
Idea
My idea is to create a custom HtmlHelper (or dependency injected translation instance, but that might be harder in this situation) which only needs the translation ID. The helper will get the language from a cookie. This way, we can simply use the following code in our views:
#Html.Translate(1337)
What i'd like to achieve, is to use the first Translate-call to scan the RazorView for all Translate-calls (with their parameters). This way, I can use a Dependency Injected Scoped instance to save all the translations to. Which means that I only have to make one database call for each requested view.
Actual question
Does this sound like a good idea, and will this be doable? I searched through the MVC source code, but can't find a way to achieve something like this. The RazorView instance in the IHtmlHelper does not seem to have list of IHtmlHelper's or something...

CanJS multiple page app

The tutorials and example I've seen are all single page application.
Can anyone give an idea or point to a resource showing how a multiple page app can be developed with CanJS?
You should be able to create a new page in whatever app framework you are using or even just static pages, and then hookup your new control and view to any element on that new page.
You want to have a separate control for each module, so you might have separate controls even on a single page if you have, for example, a filterable dropdown list, a todo list, and a login. So, in your canjs directory for your app you will have separate sub-directories for each module which will contain your control, view/s, model/s, and observe/s and unit tests. This makes them re-usable, easier to test, and since they are modular if one part of your app breaks it won't take down all functionality. Once you get the hang of that incorporate AMD style loading of your assets with stealJS which is made by Bitovi - the CanJS creators.
https://github.com/bitovi/steal
If you want to manipulate the location.hash without actually changing pages or manaage browser history and client state you should check out can.route:
http://canjs.com/docs/can.route.html

JavaFX How to switch from different windows

I'm making a JAVAFX application in which I first want users to log in (in the very first prompted window) and, depending on the success or not, I want to create a different huge window which will be the global interface of the app.
I try to do it following the MVC pattern, though in JavaFX it does not seem to be a very clear separation. I have the views (two xml files), one controller (for both the views and the model) and the model.
Since the very first scene is always created in the main class, how can I hide that one and create a new one (corresponding to the global interface) when the user presses the login button??
Thank you very much in advance!

When to use more than one Sammy.js application?

As I'm learning about Sammy.js I read that you can have several Sammy.js applications in the same page, each bound to a different element (i.e. div). I would like to understand why would this be useful.
I read in another post that only forms inside a bound element will trigger the route change, I'm thinking this could be used to modularize your application. Is there another use case beside this? Could you provide an example of how to modularize your application in this way?
We implemented a component similar to Sammy in our Silverlight application some time ago. The similarity is in that both represent a kind of a simple browser that can be bound to a UI region. The approach gave us several benefits:
We had an extensible way to add new content implementations. I mean that we could add plugins to our app that contained new forms/views which the application core had no knowledge about.
We could easily implement composite views, e.g. dashboard that were able to show any view implemented in any module. Including themselves. (A-ha, we had created recursive dashboards that worked until the app hit the memory limit. Kind of Inception. :))
Sammy can be used to reach these goals as well.
However, you must understand that from all Sammy applications running on a page, only one can be bound to the browser location bar. Others will have their location visible only to javascript, or you'll need to render location bars for them on the page.

MVC for a UI Heavy App

Is MVC architecture appropriate for an app that is a UI centric app?
Example: you want to build a basic flowchart app. Does it make sense to make the GUI components the view, the "node" and "line" objects part of the model, and the click handlers the controllers?
It feels weird to me because there is not much functionality in the model here...
In your case, M is definitely not needed. So you can skip it. Nobody is forcing you to comply with MVC.
If you're using a MVC framework, then don't use features specific to M. Simple. :)
I think it would be pretty useful to use mcv in your project instead!
You have to store somewhere the input data of your charts so a model object would be ideal for that.
The view class would be a template for the boxes and every instance would have is coordinates.
Separating the data from the boxes view would allow you in the future to change aspect and behaviour of the box view without having to touch the data.
In the end you have to consider the mvc pattern not as something that help you build your application in the current state, but a way to have a clean design that you can change and improve without having to rewrite everything. So if you want to build an app that is going to grow go with MVC.

Resources