JavaFX How to switch from different windows - model-view-controller

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!

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...

JavaFX application with multiple fxml files

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

How to have 1 controller for 2 segues in Xcode

i have one simple question. I am building an app in Xcode 5. Part of the app is the typical login screen and the register screen and a database which stores username and password. My problem is that i don't want to write Sqlite code in both screens (in both view's controllers). What i want is to have the "databaseViewController.h and .m" controlling both the login controller and register controller. My question is : How do i do that? Im not asking for code, but short similar examples would be very helpful!. I am using storyboards if that helps too
What i want is to have the "databaseViewController.h and .m" controlling both the login controller and register controller
A common approach is to move the data access stuff out of your view controllers and into a data model (that's the M in MVC) that both view controller can talk to. Your model would have method to log in, register, tell you whether the user is already registered, etc. That leaves your view controllers to do what they do best: manage their respective view graphs and deal with user input. Maybe you already have some sort of data model, in which case the user registration and login functions can just be added to it. Otherwise, have your app delegate set up your model when the app starts up and share it with the view controllers that need to know about it.
To answer your question indirectly: If your goal is simply to share code between these two screens, you may find it easier to extract that code into a separate class, like AuthenticationManager or something, which you then use from your two different view controllers.
One common pattern for shared service objects like this is to hang them off of your application delegate. That is, add a property (e.g. authManager) to AppDelegate and then in your view controller(s), access it as [UIApplication sharedApplication].delegate.authManager.

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

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.

Resources