Don't know if anyone's still interested in this topic but I was able to get dojo working with liferay by doing the following. Figured I'd post it up here in case anyone else was still messing with this.
I wanted the logic contained in the portlet so I didn't have to enforce a theme.
I tossed dojo into my portlet's docroot /js directory of my portlet.
Grabbed a simple dojo example and put in in view.jsp:
1<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
2
3<portlet:defineObjects />
4
5<button id="progButtonNode" type="button"></button>
6<div id="result1"></div>
7
8<button dojoType="dijit.form.Button" type="button">
9 Click me too!
10 <script type="dojo/method" event="onClick" args="evt">
11 // Do something:
12 dojo.byId("result2").innerHTML += "Thank you! ";
13 </script>
14</button>
15<div id="result2"></div>
Updated liferay-portlet.xml to include dojo:
1 <portlet>
2 <portlet-name>dojo-test</portlet-name>
3 <icon>/icon.png</icon>
4 <instanceable>true</instanceable>
5 <header-portlet-css>/js/dojo/dijit/themes/soria/soria.css</header-portlet-css>
6 <header-portlet-javascript>/js/dojo/dojo/dojo.js</header-portlet-javascript>
7 <header-portlet-javascript>/js/main.js</header-portlet-javascript>
8 <css-class-wrapper>dojo-test-portlet</css-class-wrapper>
9 </portlet>
And added the following in main.js:
1
2dojo.require("dijit.form.Button");
3dojo.require("dojo.parser");
4
5dojo.addOnLoad(function() {
6 document.body.className += ' soria ';
7 dojo.parser.parse();
8
9 // Create a button programmatically:
10 var button = new dijit.form.Button({
11 label: "Click me!",
12 onClick: function() {
13 // Do something:
14 dojo.byId("result1").innerHTML += "Thank you! ";
15 }
16 },
17 "progButtonNode");
18
19 init();
20});
21
Initially, only the programmatic button would load, but adding an explicit call to dojo.parser.parse() got the declarative button working too.
It still has an issue when the portlet is initially added to a page, but every time the page is browsed to after that it seems to be working fine.
Por favor, faça login para denunciar.