Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » [SOLVED] How-to ? URL formatting with deeplink and parameters
[SOLVED] How-to ? URL formatting with deeplink and parameters [message #1752048] Wed, 18 January 2017 09:59 Go to next message
Eclipse UserFriend
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 #1752069 is a reply to message #1752048] Wed, 18 January 2017 14:34 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2426
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
here is an example how to obtain the deep link id [1]. About your second question - you want to restart the application (change the URL) with some more parameters... right? You can do this by executing a JavaScript with JavaScriptExecutor like:
"window.location = <your new URL here>"

[1] http://git.eclipse.org/c/rap/org.eclipse.rap.git/tree/examples/org.eclipse.rap.examples/src/org/eclipse/rap/examples/internal/MainUi.java#n98

HTH,
Ivan
Re: How-to ? URL formatting with deeplink and parameters [message #1752081 is a reply to message #1752069] Wed, 18 January 2017 16:29 Go to previous messageGo to next message
Eclipse UserFriend
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 #1752102 is a reply to message #1752081] Wed, 18 January 2017 18:59 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 221
Registered: February 2011
Senior Member
I use BrowserNavigation to access the content after the # in the URL

I add a listener in the entry point

			BrowserNavigation nav = RWT.getClient().getService(BrowserNavigation.class);
			nav.addBrowserNavigationListener(new BrowserNavigationListener() {
				public void navigated(BrowserNavigationEvent event) {
					String state = event.getState();
Re: How-to ? URL formatting with deeplink and parameters [message #1752135 is a reply to message #1752102] Thu, 19 January 2017 07:45 Go to previous messageGo to next message
Eclipse UserFriend
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 #1752212 is a reply to message #1752135] Thu, 19 January 2017 21:52 Go to previous messageGo to next message
Chris Fairhall is currently offline Chris FairhallFriend
Messages: 221
Registered: February 2011
Senior Member
I add the listener in the createUI method of my EntryPoint implementation

With E4... perhaps you could subclass E4EntryPointFactory and override it's create method:
public EntryPoint create() {
  EntryPoint wrapped = super.create();
  return new EntryPoint() {
    public int createUI() {
      .... add listener here....
      return wrapped.create();
    }
  };
}
Re: How-to ? URL formatting with deeplink and parameters [message #1752605 is a reply to message #1752212] Wed, 25 January 2017 15:14 Go to previous message
Eclipse UserFriend
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! Cool

I hope the full workaround will help someone else!
Thanks again for your help!
Previous Topic:Fatal error in connection with ToolTip
Next Topic:UISession not closed
Goto Forum:
  


Current Time: Fri Apr 19 19:57:25 GMT 2024

Powered by FUDForum. Page generated in 0.03127 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top