Dojo AMD and portlet-client-model - dojo

I'm using Dojo 1.9.1 AMD with WebSphere 8 portlets and can't figure out how to continue to leverage the WebSphere mechanism for getting/setting user's portlet preferences. Prior to moving from pre-AMD Dojo (1.6) to Dojo 1.9.1 AMD, I was including at the top of some JSP files these lines:
<%# taglib uri="http://www.ibm.com/xmlns/prod/websphere/portal/v6.1/portlet-client-model"
prefix="portlet-client-model" %> <portlet:defineObjects/>
<portlet-client-model:init>
<portlet-client-model:require module="ibm.portal.xml.*"/>
<portlet-client-model:require module="ibm.portal.portlet.*"/>
</portlet-client-model:init>
which get converted/generated into these lines at run-time:
<script> if(typeof dojo=='undefined') {
document.writeln("<scr"+"ipt src='/wps/portal_dojo/v1.4.3/dojo/dojo.js' ></scr"+"ipt>");
} </script>
<script>dojo.require('ibm.portal.xml.xpath'); dojo.require('ibm.portal.xml.xslt');</script>
<script>dojo.require('ibm.portal.portlet.portlet');</script>
<script>if(typeof(ibmPortalConfig) == "undefined") {ibmPortalConfig = {contentHandlerURI: "/wps/mycontenthandler/urs/!ut/p/digest!q8eCn6qc7fl2VjdmXXlayA/nm/oid:wps.portal.root"};} else if(!ibmPortalConfig["contentHandlerURI"]) {ibmPortalConfig["contentHandlerURI"] = "/wps/mycontenthandler/urs/!ut/p/digest!q8eCn6qc7fl2VjdmXXlayA/nm/oid:wps.portal.root";} </script><div id='com.ibm.wps.web2.portlet.root.Z7_HHGGGIO0JGPN00AI72U5E530O2' style='display: none;'>/wps/mycontenthandler/urs/!ut/p/digest!q8eCn6qc7fl2VjdmXXlayA/pm/oid:--portletwindowid--#oid:Z6_HHGGGIO0JGPN00AI72U5E530G4</div>
<div id='com.ibm.wps.web2.portlet.preferences.Z7_HHGGGIO0JGPN00AI72U5E530O2' style='display: none;' pageid='Z6_HHGGGIO0JGPN00AI72U5E530G4' configid='Z3_HHGGGIO0JGPN00AI72U5E53085' editdefaultsid='Z5_HHGGGIO0JGPN00AI72U5E530O6'
></div>
<div id='com.ibm.wps.web2.portlet.user.Z7_HHGGGIO0JGPN00AI72U5E530O2' style='display: none;'>/wps/mycontenthandler/urs/!ut/p/digest!q8eCn6qc7fl2VjdmXXlayA/um/secure/currentuser/profile?expandRefs=true</div>
which then allowed me to use javascript for getting and setting user portlet preferences. When I try using this same technique with Dojo 1.9.1 AMD, the same code that is generated above causes a javascript error complaining that the "dojo.require" is not a function.
With the improved Dojo AMD, I no longer have any calls to "dojo.require" like I used to, so I haven't encountered this issue, but these WebSphere custom tags automatically generate "dojo.require" calls that are now failing.
Do I need to try to mix the old pre-AMD inclusion of dojo.js with the preferred AMD inclusion calls? Has anyone encountered this issue yet?
Any help is appreciated. Thanks.

Your main problem is that you're using an old taglib. If I look at the URL I see that you're using a v6.1 taglib, which uses Dojo 1.4.3 and that is obviously outdated. Try to replace the taglib with:
<%# taglib
uri="http://www.ibm.com/xmlns/prod/websphere/portal/v8.0/portlet-client-model"
prefix="portlet-client-model" %>
I suppose that should generate some more appropriate code, compatible with the latest releases. You will probably have to update some libraries on your classpath as well.
Also, if you're using WebSphere Portal 8, then only Dojo 1.7 is supported officially, so make sure you're not using different versions here. WebSphere Portal 8.5 supports Dojo 1.9 (uses 1.9.3 to be exactly), but from your question it was not clear if you're using v8 or v8.5.
If you want to change the Dojo configuration and set async: false, that's possible, but you will have to set it before dojo.js is loaded. That means you will have to edit theme.html and the localized themes (for example theme_en.html) to add the following content above the co:head dynamic content spot:
<script type="text/javascript">
dojoConfig = {
async: false
};
</script>
<link rel="dynamic-content" href="co:head">
Be careful though, if you set it, you might break something, I don't know if IBM has their own configuration that includes custom packages or not, but if they do and you're overriding that configuration, then it might lead to errors.

Related

VueJS not rendering in IE11

I have a really large portion of our site written in VueJS. It was brought to my attention that it does not load in IE 11 (or Safari 9 and below). Unfortunately, IE 11, still accounts for 10% of traffic to the site.
After adding in polyfill and fixing some other errors in the developer console for IE11 the site still doesn't load. I see only a blank page. I set the compatibility mode to edge, nothing still. The console is clear of errors, only a few warnings. I am indeed running this through es2015 + babel-polyfill using gulp.
Has anyone dealt with this before? I am afraid I will have to start stripping down the application piece by piece until I isolate the code or element causing the problem. That could take days seeing as IE 11 gives me no debugging information.
The issue here was ES6 style JavaScript within the markup. Example:
<div class="tabs tab_select" data-group="tabs" data-ref="room" v-on:click="(event) => { toggleTab(event, property) }">
Needed to be:
<div class="tabs tab_select" data-group="tabs" data-ref="room" v-on:click="toggleTab(event, property)">
I found that my website was automatically running in compatibility mode as all sites on our intranet do.
What fixed the issue for me was using a meta tag setting the target to the version I needed (I needed to target a min of IE 10).
<meta http-equiv="X-UA-Compatible" content="IE=10" />
Put that on your index.html
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.5/bluebird.min.js"></script>

does dojo config support requirejs bundles

Does dojo config support requirejs bundles?
Introduced in RequireJS 2.1.10: allows configuring multiple module IDs to be found in another script. Example:
requirejs.config({
bundles: {
'primary': ['main', 'util', 'text', 'text!template.html'],
'secondary': ['text!secondary.html']
}
});
require(['util', 'text'], function(util, text) {
//The script for module ID 'primary' was loaded,
//and that script included the define()'d
//modules for 'util' and 'text'
});
That config states: modules 'main', 'util', 'text' and 'text!template.html' will be found by loading module ID 'primary'. Module 'text!secondary.html' can be found by loading module ID 'secondary'.
In Dojo 1.8 modules were converted to AMD format, however dojo uses some "special loader plugins" which are still in draft and could be not fully compatible with RequireJS. On RequireJS documentation it is suggested to use Dojo's AMD loader instead.
Related doc from Dojod bug tracker ticket 15616.
Please note in case you need to "build" your dojo application you should use dojo util and app.profile.js,where you can specific a list of modules to "bundle" there.
I would suggest to have a look at this dojo-boilerplate as starting point for your dojo build configuration: https://github.com/csnover/dojo-boilerplate
A useful resource on the dojo build can be also found here: https://dojotoolkit.org/reference-guide/1.10/build/

(0x800a138f) Unhandled exception in IE8 after adding BreezeJS to Durandal project

I'm hoping someone with some experience in Breeze/Durandal 2 on .NET 4.0 will be able to assist me with this error, as I'm pretty new to the mix.
I've been working on a Durandal 2/KO/Require SPA project that lately has been compiling fine and running on my IIS7. I need this app to be compatible with IE8, so I imported the shim and sham js libs as such:
<!-- ECMAScript 5 compatibility shims for IE8 -->
<!--[if lt IE 9]>
<script src="lib/ie8/html5shiv.min.js"></script>
<script src="lib/ie8/respond.js"></script>
<script src="lib/ie8/es5-shim.min.js"></script>
<script src="lib/ie8/es5-sham.min.js"></script>
<![endif]-->
<script src="lib/jquery/jquery-1.9.1.min.js"></script>
<script src="lib/knockout/knockout-3.1.0.js"></script>
<script src="/Scripts/q.min.js"></script>
<script src="/Scripts/breeze.debug.js"></script>
<script src="lib/bootstrap/js/bootstrap.js"></script>
I also need to be able to access data from a DB so I tried adding BreezeJS to the mix. According to Breeze's documentation, in order for this to work I had to remake the project in VS as ASP.NET MVC4 Project using the Empty Template. After that I imported the Breeze files using NuGet:
Install-Package Breeze.WebApi
Then I added in my pre-existing views, controllers, libraries, css, etc. to the newly created project. Now when I compile using IE8 I get the following error. This error does not show up for Firefox or Chrome:
Unhandled exception at line 125, column 13 in
http://localhost:64185/lib/durandal/js/composition.js
(Edited for readability)
SourceMap D:\localdev\TestMVC4\TestMVC4\lib\ie8\es5-shim.map read failed:
Could not find file 'D:\localdev\TestMVC4\TestMVC4\lib\ie8\es5-shim.map'.
SourceMap D:\localdev\TestMVC4\TestMVC4\lib\ie8\es5-sham.map read failed:
Could not find file 'D:\localdev\TestMVC4\TestMVC4\lib\ie8\es5-sham.map'.
Unhandled exception at line 125, column 13 in http://localhost:64185/lib/durandal/js/composition.js
0x800a138f - Microsoft JScript runtime error: 'route' is null or not an object
I thought this might be a compatibility issue with JQuery so I attempted different versions there. I've made sure that my DocType is set to:
<!DOCTYPE html>
and that I have the following meta tag:
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
However I doubt either of those would cause issues with IE8 and Durandal. Has anyone else experienced a similar issue to mine? Am I experiencing this error because I haven't configured something on the MVC4 side?
Any advice would be greatly appreciated.
Thank you
After further digging into the Durandal composition.js I found that the skipActivation parameter in the "tryActivate" function was undefined, which resulted in the error. I'm pretty sure this problem is a result of IE8 support from Durandal, so I went ahead and scrapped IE8 and I am now developing for IE9 and up.
This isn't a fix, but I've had enough headaches with this and I will be moving on ...

How can you include a javascript files from a CDN in Jasmine?

When using Jasmine in a Rails project, to keep the dependencies consistent in my Jasmine specs, I want to pull jquery from a cdn as is done on the real page. I try to do that like so, in my Jasmine.yml file:
helpers:
- http://code.jquery.com/jquery-1.9.1.js
However, this never works, as when viewing the source of the localhost:8888 I get:
<script src="/__spec__/http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
How do you this correctly?
as answered in https://github.com/pivotal/jasmine-gem/issues/135
I wrote a helper to load external javascripts. It's not the best solution (i would prefer config file use) but it works for me.
var head = document.getElementsByTagName('head')[0];
var jQueryScript = document.createElement('script');
jQueryScript.setAttribute('type', 'text/javascript');
jQueryScript.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
head.appendChild(jQueryScript);
#emrox's answer is correct and works for jasmine 2.0.
However in jasmine 2.1.3 it doesn't. This is due to the fact that when the tests are run(i'm using Chutzpah) "http:" isn't pre-pended to the CDN reference. It is in version 2.0 of jasmine.
The fix I implemented that worked involved the following line of code:
jQueryScript.setAttribute('src',
'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
Hopefully this helps someone before they decide to downgrade to 2.0!
Issue 135 made it so you can list CDN entries in your jasmine.yml file. e.g.
src_files:
- http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js
- http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js
- lib/javascript/**/*.js

Loading Dojo Library from AOL and Widget Codes from Local?

I just started to learn Dojo. I followed one site Widget example with some different ways to load Dojo libraries. I like to use AOL reference to load dojo.js like this:
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.2.0/dojo/dojo.xd.js">
</script>
and saved my widget codes in local web server like this:
scripts/
myWidget/
widgetExample.js
...
test.html
where widgetExample.js contains my widget class codes, and test.html is my testing page. The error message I got is: "uncaught exception: Could not load cross-domain resources: myWidget.widgetExample ...". I am not sure if I have to load dojo package locally? I really like to separate dojo library package as they are or loaded from AOL and only put my own codes in a local path. I tried to google about different domain loading, baseScriptUrl, and moduleMapping? Still not be able to figure out. Thanks for any detail instructions if any.
This may help: http://dojotoolkit.org/forum/dojo-core-dojo-0-9/dojo-core-support/xdomain-usage-dojo-loading-not-detecting-local-modules
The summary is: you need a djConfig item registering the modulePaths you want to be local, and specify a baseUrl to "trick" Dojo into thinking it knows where those paths are relative, across hosts.
djConfig = { modulePaths: { "mine":"/js/mine" };
then you can dojo.require("mine.Thing") from /js/mine/Thing.js
Regards,
Peter Higgins