Pular para o conteúdo principal

Postagens

Mostrando postagens com o rótulo javascript

Adding dynamic properties to a Javascript object in a GWT + JSInterop context

GWT is a framework that allows you to program the user interface of your application in Java and later it is compiled to Javascript, which will work across all browsers. The main advantage is that you don't have to care about minification of Javascript and compatibility across browsers, easy communication with server side and it is Java, you can use Java on server and client side. With Errai you have CDI (and more) on the client side, which means that you can make your application flexible and create pluggable components. GWT in its later versions introduced JSInterop , a great way to call Javascript using Java. During the compilation the Java bean will be compiled to an equivalent Javascript code. This is good for Javascript objects with static properties, but knowing Javascript you will always find cases where the attribute name is dynamic, where the attribute is created "on the fly", for example: var myObject = {     someAttributeIJustCreated : "the value...

Wildfly 10 Javascript Hello World in 2 minutes

We already talked about Nashorn, JavaFX and Javascript in this blog, but today I was surprised by the announcement that Widlfly 10 supports Javascript in the server side. I should have seen before, but only after a few months it was released I saw it on twitter ! After seeing the announcements samples , I thought I had to try it and surprisingly it took less than a few minutes to have my first script running. Here are the steps I had to follow: (I am considering you already have Java 8 installed) * Download Widlfly 10: I downloaded Widlfly 10.0.0.CR4 Application Server Distribution. See more in widlfly downloads page; $ wget http://download.jboss.org/wildfly/10.0.0.CR4/wildfly-10.0.0.CR4.zip Unzip it somewhere locally:  $ unzip wildfly-10.0.0.CR4.zip Start it "quietly": $ cd wildfly-10.0.0.CR4 & ./bin/standalone.sh > /dev/null & Create the application structure in the deployments directory $ mkdir -p standalone/deployments...

Hacking BPM Suite/jBPM 6.0.x to make REST endpoints available as a Javascript API

You might know that BPM Suite/jbpm 6.0.x(which difference I explained in this post , from now I will only mention BPM Suite) has a great REST API to interact with processes and tasks. If you want to explore the API endpoints, there's a "hidden" page with a summary of all endpoints at http://localhost:8080/business-central/rest-api.jsp: If you want to consume this API you must either create a client and/or use the remote Java API . If you want to consume it from javascript, you need to do some coding in order to get the data from the API. But there's a short way using the RESTEasy Javascript servlet . In my example I am using JBoss EAP 6.1, although this should be possible with other application servers, I will focus only in BPM Suite 6.0.3 installed in JBoss EAP. To enable the servlet, first edit the file   standalone/deployments/business-central.war/WEB-INF/web.xml and add the RESTEasy javascript servlet declaration: Now after you start BPM Suite the A...

JavaFX apps using Javascript and Gainda

In my last posts I've worked the with Nashorn Javascript engine to create JavaFX application. It's great to work with JavaFX and Javascript, however, we can't forget that a boring part of the javascript code is that we have to import Java classes do be used and this can be a tedious things because you just want to script the view... See some examples of imports I had to use in my last projects var Scene = Java.type('javafx.scene.Scene') var VBox = Java.type('javafx.scene.layout.VBox') var Label = Java.type('javafx.scene.control.Label') var TextField = Java.type('javafx.scene.control.TextField') var PieChart = Java.type('javafx.scene.chart.PieChart') var TableView = Java.type('javafx.scene.control.TableView') var TableColumn = Java.type('javafx.scene.control.TableColumn') var PropertyValueFactory = Java.type('javafx.scene.control.cell.PropertyValueFactory') var SearchService = Java.type('org.jugvale.sent...

Another World Cup App... Using JavaFX, FXML, Javascript, CSS

The World Cup Brazil is happening! It's exciting to see people from all over the world visiting my country! Today I decided to create another World Cup App, this time I'll use JavaFX, but I won't write any Java code . It's a simple app to visualize all the world cup matches and click on a game for details about it. I spent less than 3 hours working on the core of the application and a few more hours working on the details. Getting the resources to create the App By resources I meant images and to do this I downloaded all the flags images from Fifa site. It was a small and easy scrapping. Notice that all images are in under the following URL:  http://img.fifa.com/images/flags/4/{CODE}.png. To download all flags I used the following Python Script: import urllib2 codes = open('countries_codes.txt', 'r') for line in codes:         code = line.replace('\n', '').lower() + '.png'         img_url = 'http://img.fifa.com/ima...

Writing JavaFX apps using Javascript with the Java 8 Nashorn engine

Java 8 was just a great release! We already talked about Lambdas and created JavaFX 8 apps on this blog. Bruno Borges created a fx2048 , a JavaFX version of the famous 2048 game, which shows Lambdas and the Stream library usage. Today I'll rewrite the Sentiments App view in Javascript using the new JS engine named Nashorn , one of the exciting Java 8 new features. Loading the Script We load a file with the view contents, but before doing this, we add the main Stage so it can be referenced from the javascript file. That's enough for the Java part! package org.jugvale.sentiments.view; import javafx.application.Application; import javafx.stage.Stage; import javax.script.*; import java.io.FileReader; public class AppJS extends Application{ private final String SCRIPT = getClass().getResource("/sentimentsView.js").getPath(); public static void main(String args[]){ launch(args); } @Override public voi...

Playing with HTML 5 Canvas: A particle generator

Unfortunately my original site is broken and I lost my app - you can check this post from Daniel Shiffman instead I know this is a blog that was supposed to have JavaFX stuff, but I'm playing with HTML 5 last days due a book I bought in Amazon :). It's been cool to play with HTML 5, and JavaScript, but after reading and creating some things with it, I realized that I like JavaFX for graphical things, because it has a lot of built in special effects and transitions. Also in JavaFX the view components can be directly handled, with no needs to get it from HTML. What I'll show in this post is a simple particle generator which was inspired in Lucas Jordan's book JavaFX Special Effects . In charpter 2 of this book some particles systems are presented. The code of the particle generator I created could be much better, I know that, but it was a test and If I start to improve things and add new controls I would never finish it, so I decided to put a end on it. The app...