I am trying to use d3-wordcloud(https://github.com/jasondavies/d3-cloud) in my GWT project. I included this in my .html file:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" language="javascript" src="d3.layout.cloud.js"></script>
<script type="text/javascript" language="javascript" src="main.js"></script>
Where 'main.js' has a method which contains this code:
d3.layout.cloud().size([width, height])
.timeInterval(20)
.words(word_entries)
.fontSize(function(d) { return xScale(+d.value); })
.text(function(d) { return d.key; })
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.font("Impact")
.on("end", draw)
.start();
When I try to call the method from the .html file, the word cloud is generated fine. But when I do it from a java file (with $wnd), I get this error:
Uncaught TypeError: d3.layout.cloud is not a function' error
I think this might be because the d3.layout.cloud.js is written in node js and GWT doesn't know how to work with it.
Is that the reason? Is there a workaround?
Additional info: I use GWT 2.7. Good with java. Zero node js skills!
Feels like you need to simply use cloud()... instead of d3.layout.cloud()...
See line 10: https://github.com/jasondavies/d3-cloud/blob/master/examples/node.js
Related
I have a jsp in Eclipse (Kepler SR2) and it's giving me a bunch of errors on this bit of code...
<script type="text/javascript">
$(document).ready(function () {
if (Boolean(${actionBean.saveSuccess})) {
$('#myTextField').focus();
}
});
</script>
It seems that the parser doesn't like me using EL in the middle there with ${actionBean.saveSuccess} to get at a java variable, though the code works correctly.
Is there some way to escape things so that the parser doesn't complain? Or possibly another way to accomplish the same result without angering the parser?
<script type="text/javascript">
$(document).ready(function () {
var a = '${actionBean.saveSuccess}';
if (a == true) {
$('#myTextField').focus();
}
});
</script>
if ${actionBean.saveSuccess} gives you boolean value than above code helps you
try this code it will surly help you
I would like to use jsTree inside of my Liferay portlet, but everytime the script gets executed I get an error:
TypeError: treeContainer.jstree is not a function # localhost:8080/web/guest/home:14
I understand that it doesn't have the JS file available for use, so I've tried these two approaches, but niether of them works.
First: Include it directly by adding
<script type="text/javascript" src="jquery.jstree.js"></script>
into the JSP. Although I can see it being "linked" in my IDE, after building and deploying it's unavailable (duh).
Second: Editing it in the liferay-portlet.xml like this:
<portlet>
<portlet-name>myPortlet</portlet-name>
<instanceable>false</instanceable>
<!-- other mappings here -->
<header-portlet-javascript>my/resource/folder/myPortlet/jquery.jstree.js
</header-portlet-javascript>
</portlet>
But even if I edit it in like this I get an 404 in the browser console.
Function used in the JSP:
<script type="text/javascript">
$(".tree-search").click(function(){
treeContainer = $(this).siblings('.tree-container');
// correct data is taken from ${jsonFake}
treeContainer.jstree({
"plugins":["themes","html_data","ui"], "json_data": { data: ${jsonFake}}
});
treeContainer.show();
treeContainer.animate({
opacity: "1"
}, 750);
});
</script>
What am I doing wrong, please?
This seems like path issue:
Create a folder named js inside docroot and put this file there.
Add script src like:
<script type='text/javascript' src='/js/jquery.jstree.js'></script>
add the js file in portal_normal.vm file in your current theme .like
<script type="text/javascript" src="jquery.jstree.js"></script>
I have a javaScript tag:
<!-- Begin ParsTools.com Prayer Times Code -->
<script type="text/javascript" language="javascript" src="http://www2.parstools.com/oghat/oghatwhite.php"></script>
<script language="javascript">
var CurrentDate= new Date();
var JAT= 1;
function pz() {};
init();
document.getElementById("cities").selectedIndex=12;
coord();
main();
</script>
<!-- End Prayer Times code -->
I want to run this script in java and receive the html document that server sends in response. How can I do this? I also need to parse the received document and extract some special tags.
thank you.
The easiest way I know is using HtmlUnit.
WebClient htmlunit = new WebClient();
HtmlPage page = htmlunit.getPage("http://www.google.com");
//executing the javascript and getting the new page
page = page.executeJavaScript("<JS code here>").getNewPage();
more info: http://www.aviyehuda.com/2011/05/htmlunit-a-quick-introduction/
Sajad/Future visitors,
You may look into Jakarta Bean Scripting Framework (BSF) to run your javascript even as standalone code if using older java version (< 1.6, later versions of java have it embedded)
I want to access model items by index from JavaScript into a Play Framework template:
<script type="text/javascript" charset="utf-8">
window.onload = function()
{
var cl = ${colors.size()};
int i = 0;
for (i=0;i<cl;i++)
{
labels = labels + "${colors.name.get(i).escapeJavaScript().raw()}";
}
}
</script>
My problem is that this loop throws an exception:
IndexOutOfBoundsException : Index: 12, Size: 4
Nota 0: model = Color.
Nota 1: the size is 4.
Nota 2: if I test with a fixed number instead of variable i it is ok, but this is not what I need.
Cannot get why it does not work.
You try to use Groovy inside a Javascript loop which is wrong.
Remember your Groovy code (inside ${}) is evaluated by the Play templating on the server side and result of an HTML page returned to the client, and the Javascript is evaluated on client side (by the browser, not on your server).
maybe you want to do something like :
<script type="text/javascript" charset="utf-8">
window.onload = function()
{
labels = [#{list colors.name}"${_.escapeJavaScript().raw()}"#{if !_isLast},#{/if}#{/list}];
}
which is still dangerous if you don't understand what it does,
prefer using a simple AJAX request and the renderJSON method for dynamic loadings.
I'm taking my first steps to explore Spring MVC 3 (annotation driven) and the JSON functionality that it supports.
1) In my JSP page I want to click a link that retrieves JSON
$("a[class=simple2]").click(function() {
$.getJSON("checkName.html", function(contacts) {
alert(contacts);
});
return false;
});
2) The method that gets called that should return the JSON
#RequestMapping(value = "/checkName")
public #ResponseBody Contact checkName() {
List<Contact> contacts = this.userService.retrieveAll();
return contacts.get(0);
}
When this return gets triggered the DispatcherServlet catches an exception:
org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
After searching some I read that the Jackson jar (http://wiki.fasterxml.com/JacksonDownload
jackson-all-1.6.1.jar) needs to be added to the project (or server? I tried both)
Any ideas? Thanks!
It seems a fresh start this morning (and other posts here) already got the problem fixes!
I only have jackson-all-1.6.1.jar added now to my project and added to my dispatcher xml which seems all that was necessary...
But I'll quickly add another question then! :)
I'm having trouble accessing javascript files (and probably any other files aswell) in my project. From WEB-INF/jsp/home.jsp I wanne to call my javascript file in /WEB-INF/resources/jquery-1.4.3.js
my dispatcher is defined like:
< servlet-name>dispatcher< /servlet-name >
< url-pattern>/< /url-pattern>
and I've added
script type="text/javascript" src="/resources/jquery-1.4.3.js">
script type="text/javascript" src="/jquery-1.4.3.js">
script type="text/javascript" src="/WEB-INF/resources/jquery-1.4.3.js">
script type="text/javascript" src="SpringMVC/WEB-INF/resources/jquery-1.4.3.js">
< script type="text/javascript"
src="${pageContext.request.contextPath}/resources/jquery-1.4.3.js">< /script>
etc all do not seem to work.