[Logo] IT Mill Toolkit Forum
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
How to update application URI on the fly so bookmarks are usable?  XML
Forum Index -> General Help
Author Message
Jani Laakso



Joined: 05/03/2007 16:44:17
Messages: 99
Location: Finland
Offline

One of our users asked from me how to update Application URI when view changes? They would like to add e.g. "/EmployeeView?employeeId=15" to URI when an employee view is opened and instantiated with employee id 15.

This would allow users to bookmark application "navigation state" which is pretty useful feature in most applications (especially if you are using single sign-on and using bookmark does not require you to login).

I do not know how to do this, has anyone tried this?

--
Jani Laakso, Toolkit Developer, IT Mill Ltd
[WWW]
Marc Englund


[Avatar]

Joined: 07/03/2007 15:18:36
Messages: 47
Location: Turku, Finland
Offline

You can do that with a parameter (or uri) handler, but please note that this will require a full page refresh. You can not change the url without reloading the page - with one exception: the hash. You could use # in the url to change it without requiring a page refresh.
Code:
http://localhost:8080/myapp#some-direct-link


I have not tried, though...

Best Regards,
Marc
[WWW]
Jani Laakso



Joined: 05/03/2007 16:44:17
Messages: 99
Location: Finland
Offline

Marc Englund wrote:
You can do that with a parameter (or uri) handler, but please note that this will require a full page refresh. You can not change the url without reloading the page - with one exception: the hash. You could use # in the url to change it without requiring a page refresh.
Code:
http://localhost:8080/myapp#some-direct-link

 


So, the actual question remains How do I change URI in my Toolkit application? Is there an API for this in Toolkit or do I need to hack it myself?

--
Jani Laakso, Toolkit Developer, IT Mill Ltd
[WWW]
Joonas Lehtinen



Joined: 07/03/2007 17:31:51
Messages: 142
Location: Turku, Finland
Offline

here is an example
Code:
package test;
 
 import com.itmill.toolkit.Application;
 import com.itmill.toolkit.terminal.ExternalResource;
 import com.itmill.toolkit.ui.Button;
 import com.itmill.toolkit.ui.Window;
 import com.itmill.toolkit.ui.Button.ClickEvent;
 
 public class UriChangeTest extends Application {
 
 	public void init() {
 		final Window mainWin = new Window();
 		setMainWindow(mainWin);
 		mainWin.addComponent(new Button("Change URI", new Button.ClickListener() {
 
 			public void buttonClick(ClickEvent event) {
 				mainWin.open(new ExternalResource(getURL() + "#"+System.currentTimeMillis()));
 			}}));
 	}
 
 }
 


Jani Laakso



Joined: 05/03/2007 16:44:17
Messages: 99
Location: Finland
Offline

Thanks for reply, but this does not work for bookmarks. There is no way to catch # typed URI back to Toolkit (not by implementing Application.URIHandler or Application.getWindow(String name)). Therefore this URI change is not usable in bookmarking I think.

But, we can add e.g. /EmployeeView/12341234 to URI with this code and then catch it back in Toolkit and bookmarking into Toolkit applications work! Side-effect is that using bookmarks does full page refresh but that's the way how non Ajax application "links / bookmarks" just work..

So this works:

Add button below to some layout
Code:
 // Note, ExampleApplication.getCurrent() uses ThreadLocal pattern and returns Toolkit Application instance
 		ExampleApplication.getCurrent().getMainWindow().addComponent(
 				new Button("Go to EmployeeView and set URI too", new Button.ClickListener() {
 					public void buttonClick(ClickEvent event) {
 						ExampleApplication.getCurrent().getMainWindow().open(
 								new ExternalResource(getApplication().getURL()
 										+ "EmployeeView"));
 					}
 				}));
 


And add this to your Application

Code:
 @Override
 	public Window getWindow(String name) {
 		// See if client comes in through a bookmark
 		if (name.equals("EmployeeView")) {
 			// Set view to EmployeeView
 			getMainLayout().setMainView(EmployeeView.class);
 			return getMainWindow();
 		} else {
 			// do not forgot this, it handles Toolkit windows
 			return super.getWindow(name);
 		}
 	}
 


You could catch URI changes on handleURI too but it's cleaner to do in getWindow method. However with getWindow method you cannot as easily parse other additional information that you might want to pass for the view, e.g. which employee I should be editing right now.

Note, now you got to make sure that you do not create a Toolkit window named by "EmployeeView" because that window is never accessible because of your overridden Application.getWindow(String name) code..

--
Jani Laakso, Toolkit Developer, IT Mill Ltd
[WWW]
Jani Laakso



Joined: 05/03/2007 16:44:17
Messages: 99
Location: Finland
Offline

I have to say that application developers should think of other solutions than this even though bookmarks are very familar to many end users these days. But if you look where Mozilla Prism project is going (or even Firefox 4), you see that many browser mechanisms are fading out because of AJAX applications.

Simplest solution is to provide your "bookmark / shortcut" menu directly under Toolkit application.


--
Jani Laakso, Toolkit Developer, IT Mill Ltd
[WWW]
Marc Englund


[Avatar]

Joined: 07/03/2007 15:18:36
Messages: 47
Location: Turku, Finland
Offline

Yeah, you're right about not being able to catch # on the server. This is something we should implement, though - it would be quite useful. I'll go ahead and add a ticket for that.


[WWW]
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7 © JForum Team