Softlink Url Rewrite
JBStrap applications are Single-Page Applications (SPAs). As such, individual pages do not have their own URLs, as is the case with a regular HTML page. The user won’t be able to save or bookmark a page like they can do with a regular HTML page. To solve this, JBStrap comes with a SoftLink solution. This is enabled by default, but it can be disabled by setting the ENABLE_PAGE_URL_REWRITE parameter to false.
If SoftLink is enabled, when the user opens a page, its page ID will be displayed in the address bar as well. Users can save, bookmark, or even send this link. If this address is used to access the application, the user will be navigated to the requested page.
After creating and registering a page in the following example, you can open the page using the following URL (URL rewrite is enabled):
http://example.com/exampleApp/#examplePage
Register the above page using the examplePage pageID:
If the URL points to private contents (pages or UIs), only logged in users are allowed to view these contents. If a user is not logged in, the login screen is displayed when clicking on the URL. If a user is already logged in and also has access rights to view the requested contents, the page contents are displayed. If a user is logged in, but has no access rights to view the contents, then a notification is displayed and the user returns to the default starting page.
Using parameters
JBStrap's SoftLink solution enables you to use parameters. SoftLink parameters must be specified in runtime. The specified parameters are displayed unencrypted in the page URL. You can also programmatically read out the parameters and use them when building the page.
Modify the code for the ExamplePage in the above example so that the name specified in the parameter is displayed in the input field:
To read the URL parameter value, use the getUrlParameter()
method.
Specify the following URL to open the page:
http://example.com/exampleApp/# examplePage &name=John
The input field accepts the value of the name
parameter.
If you specify an invalid parameter, the getUrlParameter()
method returns NULL.
You can also programmatically specify a parameter value. The addUrlParameter()
method is used to set a URL parameter. In the following example, we modify the previously created code so that the name
URL parameter accepts the text in the input field.
If the parameter value to be specified is NULL, the parameter is not included in the URL parameters. If it was earlier, however, the parameter is deleted. This is how you can remove parameters from the code.
Disabling SoftLink
Disable the SoftLink solution by setting the ENABLE_PAGE_URL_REWRITE parameter to false. You can change the parameter using the parameterSettings()
method in the ApplicationStartup class. If you disable the SoftLink, only the application's address is displayed, no matter which page is open. This way, you can disallow the user to save the address of a specific page.
In the example, the URL for the application (and the related UIs) is the following if the SoftLink is disabled: http://example.com/exampleApp
Registering a page
Pages to be used by the application need to be created first, then assigned to the framework by the JBStrap addPage()
method to the Startup class (read more on this in the ApplicationStartup chapter).
In the above code snippet we used the following parameters to create a page:
- pageId: During navigation, this page ID can be used to reference the pages. These pageIds are our navigation endpoints.
- ExampleUI: When creating pages, the UI where the page will be displayed must be specified. It is possible to display the page on multiple UIs. If a page is to be displayed on multiple UIs, then the page must have multiple, unique page IDs.
- ExamplePage: The class representing the page
You can place additional parameters in the URL when using a SoftLink. Pages can use these parameters. The BasePage
class handles SoftLink URL parameters, so you only have to place or read the parameter(s) you want. Adding a URL parameter to the SoftLink:
Reading an URL parameter from the page address:
You can include this in a button click event handler or a page build method.
If you use custom parameters in the SoftLink, keep in mind that these parameters are not encrypted and can be easily modified, as they are just plain texts in the address bar. We recommend that you only use parameters that do not contain sensitive information, or do not contain information that may pose a security risk to the application.