cancel
Showing results for 
Search instead for 
Did you mean: 

How to dynamically set the URL for webview dashlet

vince20151
Champ in-the-making
Champ in-the-making
I need the functionality of a webview dashlet that displays a web page inside the dashlet. However, I need to form the URL dynamically (for example based on user login). How can I accomplish this. I would prefer a java controller since I have access to data that is specific to the user. However, I can work with Javascript controller too. Thanks.
3 REPLIES 3

zladuric
Champ on-the-rise
Champ on-the-rise
This should be a simple task. Depending on your requirements, the implementation can vary a bit, but what I would do is this:
- just copy the webview dashlet code, rename it to your own.
- remove the frontend code which allows the user to change the address (or make it optional)
just remove the markup for the Config click and remove the JS code in share/components/dashlets/webview.js which handles config click
- edit the controller (which is Javascript, but it's still easy) or just delete it and create a Java one.
- in the controller, set the config property of the URL and possibly title to render to whatever you need.
Ie: the default code for Alfresco 4.2 is

var webView = {
      id : "WebView",
      name : "Alfresco.dashlet.WebView",
      assignTo : "webView",
      options : {
         componentId : instance.object.id,
         webviewURI : model.uri,
         webviewTitle : model.webviewTitle,
         webviewHeight : model.height,
         isDefault : model.isDefault
      }
   };
.
Just change the <strong>model.uri</strong> and <strong>model.webviewTitle</strong> to your constructed url.

But all of this seems to be so you can load some custom web, depending on the user? Because depending on what you want to show, there are easier ways.

vince20151
Champ in-the-making
Champ in-the-making
Thanks. That does seem a lot of work. What other ways would be easier? In my java code, I retrieve preferences and access settings for the user and launch a different web page or same web page but different parameters based on these settings.

zladuric
Champ on-the-rise
Champ on-the-rise
Well, all the steps are optional. You just want to update the <strong>model.uri</strong> in your controller.

This will always render that one url. But the users can then still change the url until they refresh the page. You'll override their URL on the next pageload anyway, but if you want to disable that too, then do the other steps.