r/JavaFX • u/Ok_Jackfruit_6541 • Jun 15 '23
Help Need suggestions for POS system
Hello, everyone!
I hope you're all doing well. I have developed a REST API backend service for my own restaurant and now I want to create a desktop application for this system. I would like the following features to be a part of my desktop application:
- Role-based authorization and page views.
- JWT token-based authentication and authorization.
- Routing for different page views.
I understand that these requirements resemble those of Angular or React applications, and that's accurate. What I'm looking for is a desktop application that functions similarly to a frontend JavaScript application.
My question is: Does JavaFX provide any support for routing and auth guard for page navigation? If it does, could you please guide me on where to start learning about it?
Thank you.
View all comments
Show parent comment
2
u/hamsterrage1 Jun 27 '23
You have to remember that every MVVM/MVC/MVP unit has some kind of purpose, and the business logic that supports that purpose goes in the Model. Business logic that is more generic than that generally goes into the Service layer.
Let's say that you have a screen with MVVM that has some customer information. The logic that fetches the customer data from the database and figures out what to do with it goes in the Model. To be clear, if the database API returns results in JSON, the Model shouldn't be seeing any of that JSON. The code that interprets the JSON and turns it into some kind of POJO object goes in the service layer. Let's call it
CustomerService, and it returns an object calledCustomer.The Model instantiates
CustomerServiceand calls some method in it that returnsCustomer. It then does stuff withCustomerthat is specific to whatever function that this MVVM construct does. That's the "business logic".Now, let's say that this screen is customer facing, and there's a requirement to show a "friendly" message on the screen - something like "Hello Customer". We want it to be casual, so instead of saying "Hello Fred Smith", it should say, "Hello Fred", or "Hello Mr. Smith".
You could argue that presentation of the name on the screen is 100% visual and clearly belongs to the View to decide how to display the data. In this case, you'll have a method in your Model called,
getCustomerName()which returns a String, and the ViewModel will call that method and use it to populate a StringProperty calledcustomerName. Then it's up to the View to create a Binding for the Label that it's using on the screen to construct the "Hello ..." display.That's all well and good for Fred Smith, but what if the name is Bobby Joe van Der Camp III Esq? This is the stuff that happens in real life, and it's not really simple any more. How do you get to "Hello Bobby Joe", or "Hello Mr. van Der Camp"?
And let's say, it's a business requirement that anyone under twenty should be "Hello Bobby Joe", and everyone twenty and older should be "Hello Mr. van Der Camp" (the age is included in the
Customerobject).What you probably should do is create a method called
Model.getCasualName()and have the ViewModel call that and put it into the StringProperty. This reflects the fact that whatever decision making that goes into determining the casual name really is, in truth, "business logic".And then, when the database is updated with
PreferredName, and theCustomerServicereturns that as a field inCustomer, that might be something that was decided to be used. So there's a new requirement that if theCustomerhas something inPreferredName, then use that, otherwise follow the old logic. Now maybe, we get "Hello BoJo" instead.The point is that these changes take place and they do NOT bubble up past the Model. The View is responsible for displaying the data that it's given, and the ViewModel is responsible for getting that data to/from the Model. Neither one of these needs to aware of changes in the structure of the database, or the data manipulation that turns raw database data into "Presentation Ready Data".