PDA

View Full Version : Ext on Java ??



chalu
27 Apr 2009, 6:38 AM
I am planning to build my first real Ext App, and I have been seriously considering using Java (instead of PHP) for the backend because of the requirements. My experience (experimantaly)
with Ext has always been with PHP e.g :



<?php

$response = array(
'success' => true,
'message' => 'Completed Update Request',
'data' => array(1, 2, 3, 4, 5, 6, 7, 8, 9)
);

print json_encode($response);

?>


I am wondering what it is like if I was to do something like this in Java. I am thinking of using Spring + Hibernate + JBoss. Would it be possible without DWR

What are your experiences / other things I need to know

Animal
27 Apr 2009, 6:50 AM
Yes, that's quite easy. You just need a JSON library which can encode beans, and Java.util.* classes into JSON.

27 Apr 2009, 7:19 AM
Ext is platform independent.


We manually write our actions. But you can use Ext Direct to take care of many of that stuff automagically.

DWR is awesome to use with java btw.

chalu
27 Apr 2009, 8:57 AM
Yeah DWR is beginning to sound interesting to me, still looking at it though, but some articles are mentioning things like 'generating javascript' and I really don't like technologies / tools that interfere :).

Another question, would you guys recommend Netbeans or Eclipse for development of a Java based Ext application. Netbeans has some good javascript support but I hear a lot of noise about Eclipse :-/:-/

27 Apr 2009, 9:12 AM
Eclipse is awesome. I don't personally use it. I started using intellij and have fallen in lovewith it.

I'm just starting to learn java, so i'm no guru. AutoComplete is awesome in all 3 of those IDEs. You can get an aptana plugin for eclipse btw, for full Ext and javascript support.

chalu
27 Apr 2009, 10:37 AM
I "left" active Java development early in 2007, so I'm rusty now. Yeah, I use Aptana for Javascript development, but javascript (in web apps) is usually developed as part of a larger project (Java / PHP / ASP.NET etc) and none of them (IDEs) handle javascript well enough like Aptana.

My experience had been to use Zend studio for Eclipse for the server-side (PHP) and then Aptana for the client-side (HTML, CSS, Javascript) but since I usually developed against a local SVN repository I had to create working copies (2) for each project, one for the PHP development with Zend Studio and the other with Aptana for the client side technologies.

I don't want to do this again, I need a better way. Yes Netbeans has good support for Javascript but it adds to your project, a copy of every API you are using to script the application, unlike Aptana that just uses a global script library reference for autocompletion.

I am persuaded to use Eclipse. I was wondering, is there a way to install Aptana as a plugin to Eclipse and use Aptana's scripting features in a JavaEE project by switching perspectives ?? tried it but could only enjoy the Aptana JS features when I create an Aptana related project.

Thanks.

Animal
28 Apr 2009, 4:31 AM
DWR generates stub functions dynamically in order to export an interface into the browser.

So you annotate a class to export methods.

Then you include a <script> in your page which pulls in a generated class from the DWR servlet. This javascript is generated on demand according to the definition and annotatinos in that class.

Then you can just call methods of that class.

Of course they don't return data, you append a callback function which receives any return value.

tim.sporcic
28 Apr 2009, 4:51 AM
There are multiple ways of using ExtJS with a Java backend. Some swear by DWR. My own experiences with it have been less then positive. I've ended up pulling it out of the last two projects and replacing with Spring Framework controllers returning straight JSON data. It was a better match for ExtJS. You can check out my sample of using ExtJS with Java/Spring (http://www.sporcic.org/2009/01/springing-around-with-extjs/) to give you some ideas.

If you're used to the lighter-weight syntax of PHP, you might also check out Groovy/Grails. You get the full power of the Java VM in a dynamic language.

chalu
2 May 2009, 8:19 AM
Really DWR is interesting, I have always tried to have a 'domain' layer (in the client too) in my Ext experimentation so my app can be structurally stronger instead of just having namespaced loose functions and and objects that just make ajax calls and update UI. With DWR I have that leverage of a Person 'domain' object in my client from my server.

One more question, DWR claims to have 'Reverse Ajax', is this the comet we've been talking about, and how does this intgrate with the Ext.direct that I hear of.

Thanks very much.

Animal
2 May 2009, 8:24 AM
Reverse Ajax allows threads running in your server to execute methods in browser sessions.

DWR handles in this either through regular polling of the server, or by pigggybacking the requests for any new reverse Ajax calls on packets which are being sent to make regular DWR calls.

We have experimented with reverse Ajax for things like broadcasting messages to logged in users, and it works well.

Obviously standard JEE sessions don't time out when being polled repeatedly, so you will have to come up with another way of detecting a "dead" session.

chalu
2 May 2009, 10:05 AM
Ext has good AOP, and I think it's because it has very good scope handling and plug points. My very first experiment with DWR seems not to honor this. How do you guys scope your DWR callback functions if needed.


// Java
package dwr.test;

/**
*
* @author chalu
*/
public class Person {

private String fName, lName;

// default constructor
public Person(){

}

public void setFirstName(String fname){
fName = fname;
}

public String getFirstName(){
return fName;
}

public void setLastName(String lname){
lName = lname;
}

public String getLastName(){
return lName;
}

public String setFullName(String lname, String fname){
setLastName(lname);
setFirstName(fname);
return getFullName();
}

public String getFullName(){
return fName + " " + lName;
}

@Override
public String toString(){
return getFullName();
}
}




<head>
<script type='text/javascript' src='dwr/interface/Person.js'></script>
<script type='text/javascript' src='dwr/engine.js'></script>
<script>
console.info("Person %o", Person); // shows all my exposed functions
var dwrApp = {};
Person.setFullName('Odili', 'Charles', {
scope: dwrApp,
callback: function(name){
console.info('scope %o, args %o', this, arguments);
console.info(name);
}
});
</script>
</head>

Firebug shows the callback scope as the argument that contains the callback. i.e the third parameter I passed to Person.setFullName.

Still looking at the docs though

Animal
2 May 2009, 11:01 AM
In DWR 2.*, you have to use createDelegate on your callback function to impose a calling scope on it.

You are using the latest version there? I though 3.* did allow a scope property of the callback object.

JamesC
8 May 2009, 12:12 PM
Animal is correct using dwr3 you can use { callback:function(data) {..}, scope: this }

I'm using dwr 3 in our app and it's working very well using most features, especially reverse ajax which is very good and the new ability to upload files directly to dwr methods (no special upload coding necessary)!

deanna
8 May 2009, 2:04 PM
...

My experience had been to use Zend studio for Eclipse for the server-side (PHP) and then Aptana for the client-side (HTML, CSS, Javascript) but since I usually developed against a local SVN repository I had to create working copies (2) for each project, one for the PHP development with Zend Studio and the other with Aptana for the client side technologies.
...


Zend Studio Eclipse is Eclipse, which is the same as Aptana. All those run Eclipse as the IDE framework base, and have addons to enhance it. The good thing here is you don't have to swap IDE's. If you have bought Zend Studio, then just add sprket to it (by Help->Software Updates->Find and Install - there are directions in the wiki on this). You can add in Java support the same way. Find out which Java addon you like and add it by the same method.