Application - AlexGPlay/Blynder GitHub Wiki
The Application class is a static facade that allows the user to interact with the core.
How to use
Launching the app
The Application has the entry point to the application in the launchApp method. This method has two signatures one wihtout parameters and one with a parameter of the interface IConfigurator, this one will be explained on its own in the Configurators page. If you want to start the app you have to invoke the launchApp method in your main.
import org.blynder.core.Application;
public class MainClass {
public static void main(String[] args) throws ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InstantiationException {
Application.launchApp();
}
}
This will lauch the main Window and try to navigate to the root path, this path must exist in a controller.
Navigating through the paths
The Application holds another pair of methods that allows the user to navigate through the different paths that are declared in the controllers. This pair of methods are the navigate with one param and with two params. We will talk first about the one without params given that the second one does the same but with a little difference. If you are in a view and want to navigate to another view you just need to call the navigate method and it will do the rest. For example, if your view is a JPanel and you want to navigate:
public class TestPanel extends JPanel {
...
public void navigateTo(String url){
Application.navigate(url);
}
...
}
This method could be invoked when you click a button and allow you to go to another path.
Now lets talk about the second one, this one has another parameter, the second parameter is a Request object, this type of object holds some properties that may be useful in a controller. Those properties are the URL, the method, the headers, params and body. You may find useful to navigate giving some information to the controller using this one.
Now that we have talked about the second one you may be asking another question: how do I navigate if I'm in an HTML? Well maybe you already have and idea, and yes, it is the standard way but with a difference. You can use href in order to achieve this and the application will internally invoke the navigate method with a request but there is a thing here. Given that we are not in a server you have to specify an schema that is not the http or https. Lets see an example:
<a href="app://some/path">Link</a>
As you have seen above the syntax is the normal href but we have to set an app:// before the path and there is not domain. In this way you can go thorughout the different paths from an html view. This also applies to AJAX requests.
Holding information
The Application class also allows the user to store some information. There is a hash that stores the information the user wants to in order to simplify the development. The methods that can be used are this ones:
- Application.set(String name, Object value)
- Application.get(String name)
- Application.remove(String name)
- Application.hasKey(String name)
As you can imagine, this ones apply directly to the hash methods, set stores an object, get gets that object, remove removes the object with that key and hasKey returns if the items is stored or not.