[SOLVED] How-to ? URL formatting with deeplink and parameters [message #1752048] |
Wed, 18 January 2017 09:59 |
Eclipse User |
|
|
|
Hello all,
I am in the process of publishing my website and I have been ask to add dynamic url formatting to be able to access a direct state of my website only using the url.
With Eclipse RAP tutorial I am able to change the url when opening a View. For example if I open the view with the Id: bacnet.TranscriptomicsView, the URL of the website will change from http://127.0.0.1:10080/Bacnet to http://127.0.0.1:10080/Bacnet#bacnet.TranscriptomicsView
Using :
BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class );
service.pushState(viewID,viewID);
My idea was then to use at the start of my application:
StringBuffer url = RWT.getRequest().getRequestURL();
But when providing this url : http://127.0.0.1:10080/Bacnet#bacnet.TranscriptomicsView
The output of RWT.getRequest().getRequestURL() is http://127.0.0.1:10080/Bacnet
Everything after the # is parsed.....
How to get the deep link after the # when starting a RAP app ?
Second: Then when I push some button in my view I want to be able to change the url to : http://127.0.0.1:10080/Bacnet#bacnet.TranscriptomicsView?param1=value1,param2=value2
And this I found nowhere how to do that with RAP ...
Even if there is a method to get the parameters has soon as they are setup:
Map<String, String[]> map = RWT.getRequest().getParameterMap();
I am using RAP E4 3.1
Someone?
Thanks!
[Updated on: Wed, 25 January 2017 15:17] by Moderator Report message to a moderator
|
|
|
|
Re: How-to ? URL formatting with deeplink and parameters [message #1752081 is a reply to message #1752069] |
Wed, 18 January 2017 16:29 |
Eclipse User |
|
|
|
Perfect answer thanks!
So for the second point I can set parameters by doing :
exec.execute( "window.location.href = 'Bacnet#"+viewId+"?param1=value1"'" );
It sets correctly the URL!
Now for the first point, I want to be able to parse the URL when opening the App. Example if I have :
http://127.0.0.1:10080/Bacnet#bacnet.InitView?param1=value1
StringBuffer url = RWT.getRequest().getRequestURL();
Will return : http://127.0.0.1:10080/Bacnet
Because as I have only one EntryPoint registered, everything after the # is parsed.
But as you suggested if I do :
JavaScriptExecutor exec = RWT.getClient().getService( JavaScriptExecutor.class );
exec.execute("window.alert(window.location)");
I got a window with the correct URL which I can now parse! Perfect....
Except I don't see how to get the JavaScript value "window.location" from the RAP platform ???
I want something like:
JavaScriptExecutor exec = RWT.getClient().getService( JavaScriptExecutor.class );
String realURL = exec.execute("return window.location")
I don't see in the MainUi.java file your provided somewhere where you get a return from a javascript
[Updated on: Wed, 18 January 2017 16:42] by Moderator Report message to a moderator
|
|
|
|
Re: How-to ? URL formatting with deeplink and parameters [message #1752135 is a reply to message #1752102] |
Thu, 19 January 2017 07:45 |
Eclipse User |
|
|
|
When do you register your BrowserNavigationListener ?
I tried to do that, but it did not work, at least in RAP E4.
Because if you try to register a BrowserNavigationListener during the configuration of the application:
public class BasicApplication implements ApplicationConfiguration {
public static String MAIN_ENTRYPOINT = "/Bacnet";
public void configure(Application application) {
BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class );
service.addBrowserNavigationListener( new BrowserNavigationListener() {
@Override
public void navigated(BrowserNavigationEvent event) {
String stateID = event.getState();
}
} );
application.addEntryPoint(MAIN_ENTRYPOINT, new E4EntryPointFactory(E4ApplicationConfig.create("platform:/plugin/bacnet.e4.rap/Application.e4xmi")), properties);
}
}
It crashes has the Client has not been create yet! So RWT.getClient throw a "Invalid thread access error.
|
|
|
|
Re: How-to ? URL formatting with deeplink and parameters [message #1752605 is a reply to message #1752212] |
Wed, 25 January 2017 15:14 |
Eclipse User |
|
|
|
Yessss!!!!!!! It works! Thanks a million for your responses!
Ok so here the final answer for E4 RAP 3.1 application.
You have to extend your EntryPointFactory like that:
public class BacnetE4PointFactory extends E4EntryPointFactory{
public BacnetE4PointFactory(E4ApplicationConfig config) {
super(config);
}
@Override
public EntryPoint create() {
EntryPoint wrapped = super.create();
return new EntryPoint() {
public int createUI() {
BrowserNavigation service = RWT.getClient().getService( BrowserNavigation.class );
BrowserNavigationListener listener = new BrowserNavigationListener() {
@Override
public void navigated(BrowserNavigationEvent event) {
Database.getInstance().setCurrentState(event.getState());
System.out.println("InitState: "+event.getState());
}
};
Database.getInstance().setNavigationListener(listener);
service.addBrowserNavigationListener(listener);
return wrapped.createUI();
}
};
}
}
I put in a singleton value the initial state: Database.getInstance().setCurrentState(event.getState());
public static Database getInstance(){
return SingletonUtil.getSessionInstance(Database.class);
}
Than when the first MPart is created you have to run something like: NavigationManagement.parseInitURL(partService);
Which implementation is like that:
public static void parseInitURL(EPartService partService){
System.out.println("Access door: "+Database.getInstance().getCurrentState());
String state = Database.getInstance().getCurrentState();
if(!state.equals("")){
// Here you parse the state by getting the parameters and part.ID and you display the part
partService.showPart(state,PartState.ACTIVATE);
}
}
You may have notice that I put the first BrowserNavigationListener in my Singleton by doing : Database.getInstance().setNavigationListener(listener);
This is a trick which I found to be able to register a new Listener afterwards to be able to activate the "previous" and "next" capability of your navigator. Because the Listener which I register for the moment is using a EPartService which has not been created yet. For this reason when the first MPart is created in your webapp you should register a new BrowserNavigationListener, like that:
BrowserNavigation service = RWT.getClient().getService( BrowserNavigation.class );
service.removeBrowserNavigationListener(Database.getInstance().getNavigationListener());
service.addBrowserNavigationListener( new BrowserNavigationListener() {
@Override
public void navigated(BrowserNavigationEvent event) {
String sourceID = event.getSource().getClass().toString();
String stateID = event.getState();
System.out.println("source: "+sourceID+" state: "+stateID);
/*
* Parse State
*/
String viewID = stateID;
Database.getInstance().setCurrentState(stateID);
System.out.println("PartService: "+partService);
MPart part = partService.findPart(viewID);
if(part!=null){
partService.showPart(part, PartState.ACTIVATE);
}
}
} );
And this how you open a view with a specific state in your webapp!
I hope the full workaround will help someone else!
Thanks again for your help!
|
|
|
Powered by
FUDForum. Page generated in 0.03127 seconds