4

Code Snippet Manager in Java and Swing

Posted by JOKe on 9/27/2009 11:40:00 PM in
Today I've try to create code snippet manager using Java and Swing. In my previous post I try to done this using WPF and C# (http://gochev.blogspot.com/2009/09/code-snipper-manager-in-c-and-wpf.html) I've just wanted to see how harder is to create the same app using Java and Swing.
First lets make some compare about the WPF and Swing version of the app.
The WPF version consists of 5 files(2 XAML files and 3 cs files with classes)

The WPF version uses XAML for the view (only 30 lines) and 8 lines in file called App.xaml.
The C# class with the logic is 208 lines of code. The Snippet model class is not 62 lines of code using C# properties and etc.

The Java version have 3 classes. One is the main class, the snippet model class 54 lines (most of them created automatically by eclipse like getters setters in C# YOU HAVE TO WRITE THEM MANUALLY) and the Logic + View class is 290 lines of code.

So in conclusion I can say that Java version is 40 lines of code more but this is because of the event handlers which are anonymous classes everywhere in my code.

Anyway the result is :
WPF app looking like this (on left) and Swing app on right:



As you can notice the WPF app looks very worse. Maybe because of the fonts which are not clear typed AND I CAN'T MAKE THEM CLEAR TYPE :) The Swing app have clear type fonts and I've included Substance look and feel because it have nice animations and hover effects.
The result is - Swing app which looks better under Windows and All OSes (WPF is only for Windows).

So if you ask me I will stick to Swing maybe it takes more lines of code for the same view but it looks better and I don't like to write and debug XML.
The Swing version of code snippet manager is available at http://code.google.com/p/snippet-manager/ it has the fallowing features:
- insert snippet from clipboard
- delete selected snippet
- insert separator
- save all snippets to XML file
- load snippets from XML file.


|
1

Java2Days conference in Bulgaria, Europe 8-9/10/09

Posted by JOKe on 9/14/2009 12:42:00 PM in ,

Java2Days conference is a brand new event in Eastern Europe to present the latest trends in Java development.

Java2Days will be held at the Inter Expo Center on 8-9 October in Sofia, Bulgaria. The conference is hosted by Insight_technologies and the Bulgarian National Academy for Software Development.

The conference is the first of its kind to be held in Eastern Europe, focused to highlight today’s cutting edge trends in building software applications with Java development tools.

Over two days, more than 600 attendees will meet world famous lecturers, engaged all year round in such events as JavaOne, The ServerSide Java Symposium, Jazoon showcasing their latest knowledge in creating more reliable, scalable and secure solutions using Java technologies in more than 20 technical sessions.

The major purpose of the event is to become a place for passionate Java developers to get in touch with the latest technologies, to become a significant part of the global Java community and to learn from the best.


Registration

Prices

VIP Pass – 175 EUR

VIP Java2Days Pass Includes:

  • Access to all sessions
  • Eco bag with advertising materials
  • VIP promoting gifts
  • Coffee breaks
  • Front row seating
  • DVD with all conference materials, video, photos and etc.
  • Q & A session with the lecturers

Standard Pass – 110 EUR

Standard Java2Days Pass Includes:

  • Access to all sessions
  • Eco bag with advertising materials
  • Coffee breaks
  • Q & A session with the lecturers

You can add to your pass:

Lunch – 10 EUR per day

The buffet lunch is in a separate hall with plenty of salads, different kinds of meats, vegetarian dishes and desserts.

Special dinner on 8th of October – 20 EUR

A dinner at a Bulgarian tavern with live folklore songs and dances. A place where one can meet with the lecturers and developers from different countries in a unique atmosphere tasting the world-famous traditional Bulgarian cuisine and drinks. We promise it will be a great unforgettable experience


You can read more about registration at http://java2days.com/pricing and http://java2days.com/registration

Agenda

Here are the main shortlisted topics that will be presented at Java2Days conference:





SpeakerSession
John WillisJava and the Cloud
Mircea MarkusJBoss clustering solutions
Reza RahmanJava EE 6 Preview
Reza RahmanEJB 3.1 Preview
Reza RahmanSpring and EJB 3 Integration
Reza RahmanRelational Perspectives for Optimizing JPA
Rob HarropModular Web Applications with OSGi
Rob HarropAdvanced Concurrency Techniques
Heath KeslerGWT Tips and Tricks for Beginners
Heath KeslerAdvance GWT Concepts
Josh LongGetting Started with Spring Integration
Josh LongJSF++
Josh LongGetting started with jBPM 4 (and Spring)
Andrew LombardiRapid Application Development with Apache Wicket
Talip OzturkClustering your application with Hazelcast
Bruno BossolaSolid design principles
Vassil PopovskiVMware and Spring Source: Brining Java to the Clouds
George MoykinOracle JRockit – Extreme and Predictable Performance with Java
Anatoli AtanasovBuilding Efficient Application Grids with Oracle Coherence

We will continue to add more new topics and new key speakers to make the conference more valuable for you. So, visit our site and stay tuned with all news about Java2Days.

If you have any questions, ideas or comments, just contact us at info@java2days.com


For news about the conference program and agenda please check out http://java2days.com/agenda and news section of the event http://java2days.com/news


|
0

XMLSerialization with C#

Posted by JOKe on 9/13/2009 06:10:00 PM in
When I first hear about XML serialization in C# I thought that it is like Java serialization but the result is XML character stream instead of the default serialization in Java/.net.
But the things are not so great.
The XML serialization in C# is good but it is not the best.
In Java the easiest way to make normal serialization is to implement interface Serializable and to be sure that all fields in your custom class are serializable. If you want to Serialize ArrayList of this objects you dont have problems because ArrayList implements Serializable.

But when you use XML serialization you dont care about Serializable interface. In Java you can make XML serialization this way : http://www.javablogging.com/serialization-to-xml/. You can see that it is simple I thought that in C# the situation is the same but it is not.
To read about serialiization in C# there is tones of info but I didn't found answer like this one in this post:
I will notice only some important aspects of this because when I try C# serialization I have missed some points of this article and i loose 30mins of searching what the problem is.

If you need to serialize ArrayList of strings no problem you can make it this way:
// Serialization
XmlSerializer s = new XmlSerializer( typeof( ArrayList) );
TextWriter w = new StreamWriter( @"c:\list.xml" );
s.Serialize( w, myList );
w.Close();

You can notice that you pass the type of ArrayList to XmlSerializer right? That is the difference.
In Java you don't need to specify what you pass it is "founded" automaticly. But in C# you need to pass all classes that you serialize or I dont know maybe most of all? You have two ways to do this:
If you want to serialize ArrayList of Strings it is ok, but if you want to serialize ArrayList of custom objects lets say Snippets you have to specify this.
For example :
private XmlSerializer serializer = new XmlSerializer(typeof(ArrayList),
new Type[] { typeof(Snippet)});

and if you have a big hierarchy like class A, Class B :A , Class C:A you have to pass all of them. For example:
new XmlSerializer(typeof(ArrayList),
new Type[] { typeof(A),typeof(C),typeof(B) });

if you ask me this is dumb. But wait there is another way and it is explicitly telling the serializer to expect the Snippet class when serializing ArrayList of snippets.
For example :
    // This attribute enables the ArrayList to be serialized:
[System.Xml.Serialization.XmlArray("Snippets")]
// Explicitly tell the serializer to expect the Snippet class
// so it can be properly written to XML from the collection:
[System.Xml.Serialization.XmlArrayItem("snippet",typeof(Snippet))]
public ArrayList listSnippets;

I don't know did you get the idea, but if you ask me Microsoft make something very easy (as you can see in the java example) harder.
But one think I can say to microsoft is that attributes for XML serializations are nice.
What am I talking about ? lets say that we want to edit the Snippet class or we can edit it.
If you leave the default implementation of Snippet:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace CodeSnippetManager
{
public class Snippet
{

public static int counter = 0;

public Snippet ()
{
counter++;
Id = counter;
}

public int Id { get; set; }

private String label;
public String Label {
get
{
return label;
}
set
{
if(value != null && value.Length > 20)
{
value = value.Substring(0, 20);
value.Replace("\r\n", "");
}
this.label = value;
}
}
public String Data { get; set;}
public Snippet(String label,String data)
{
this.Label = label;
this.Data = data;
counter++;
Id = counter;
}

public override string ToString()
{
return Id + ") "+ label;
}
}
}

Btw this class is used in my code snippet manager. So if you keep this and save ArrayList of Snippet objects the result XML looks like this:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<anyType xsi:type="Snippet">
<Id>1</Id>
<Label>ublic static int cou</Label>
<Data>ublic static int counter = 0;</Data>
</anyType>
</ArrayOfAnyType>

But you can use XmlRoot and XMLElement attributes to specify the names of the XML Elements.
If you Snippet class looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace CodeSnippetManager
{
[XmlRoot("SnippetRoot"), Serializable]
public class Snippet
{
[XmlIgnore]
public static int counter = 0;


public Snippet ()
{
counter++;
Id = counter;
}

[XmlElement("SnippetId")]
public int Id { get; set; }

private String label;
[XmlElement("SnippetLabel")]
public String Label {
get
{
return label;
}
set
{
if(value != null && value.Length > 20)
{
value = value.Substring(0, 20);
value.Replace("\r\n", "");
}
this.label = value;
}
}
[XmlElement("SnippetData")]
public String Data { get; set;}
public Snippet(String label,String data)
{
this.Label = label;
this.Data = data;
counter++;
Id = counter;
}

public override string ToString()
{
return Id + ") "+ label;
}

}
}


When you save you get this result :
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfAnyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<anyType xsi:type="Snippet">
<SnippetId>1</SnippetId>
<SnippetLabel>XmlRoot</SnippetLabel>
<SnippetData>XmlRoot</SnippetData>
</anyType>
</ArrayOfAnyType>


So as a conclusion I can say that XMLSerialization in C# maybe is harder than Java way but you have easy way to customize the result which is very good.

P.S. I've used Serializable in the Snippet class just for readability.

|
5

Code Snippet Manager in C# and WPF

Posted by JOKe on 9/12/2009 09:27:00 PM in
Hello all, today I will post a simple code snippet manager created using C# and WPF. The idea of the app is to be used when making presentations and you need to paste all kind of code snippets (html, xaml, C#, java ). The similar tool is used by Karen Corby in MIX09 presentation about creating silverlight controls.
This is my first .net application so you will see all kind of C# strangeness like using "Object" instead of "object" and String instead of "string".
Because this was my first application I choose to use WPF not WinForms because WinForms is a lot like Swing and I've wanted to see "how declarative XML for the UI is better" and I can say: "hmm ok there is some big pluses". Anyway I have little experience with Flex's MXML too and if you ask me the MXML is a lot than XAML.
The code snipper manager application lokks like this :
The view is very simple and I can say that XAML is perfect for creating a simple views and there is tones of snippets in internet for all kinds of examples like popup for example.
The application XAML looks like this :


<Window x:Class="CodeSnippetManager.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Snipper Manager" Height="355" Width="177" Topmost="True" ResizeMode="NoResize" >
<Grid Height="309">
<ListBox Margin="0,-8,0,38" Name="listSnippets" HorizontalContentAlignment="Left"
MouseRightButtonDown="listSnippets_MouseRightButtonDown"
SelectionMode="Single" SelectionChanged="listSnippets_SelectionChanged"
MouseDoubleClick="listSnippets_MouseDoubleClick">

</ListBox>
<Popup Placement="Mouse" Name="popupHint" HorizontalAlignment="Left"
VerticalAlignment="Top" IsOpen="False" AllowsTransparency="True">
<Border BorderBrush="Black" BorderThickness="1">
<Grid Background="White">
<TextBlock Background="White"
x:Name="PopupTxt"
TextAlignment="Center"
VerticalAlignment="Center">

</TextBlock>
</Grid>
</Border>
</Popup>
<WrapPanel Height="40" Name="wrapPanel1" VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Height="26" Name="menu" Width="65" Margin="5" Click="menu_Click">Menu</Button>
<Button Height="26" Name="clear" Width="65" Margin="5" Click="new_Click">Clear</Button>
</WrapPanel>
</Grid>
</Window>


Maybe you can notice that code is short and very simple, maybe simpler than MXML in Flex and a lot simpler than Swing/SWF and JavaFX. There is no code fragments on the view and etc. But what i did not understand is why all kinds of Name x:Name and other attributes are needed. The XML schemas are strangely organized if you ask me.
Anyway the project is uploaded here http://snippetmanager.codeplex.com/Wiki/View.aspx?title=Home. You can download the source and edit it if you want or you can download the release version and try to use it.
The application have the fallowing features:
- creating and adding code snippets from the clipboard
- saving sets of snippets as XML files for usage in the future
- loading sets of snippets
- delete snippet if it is inserted by mistake
Maybe you will notice strange fonts rendering ( there is no clear type ). This is because WPF 3.5 doesnt support clear type at this moment. But clear type will be supported in the incoming .net 4.0 release. If you ask me the current fonts looks even bad than the Java Swing font rendering before 1.6 update 10 which is funny.
The Expression Blend application is written in WPF too and the fonts looks also this bad but if you use dark theme (black by default) it is harder to notice the bad looking fonts. So if you want change the application color schema to darker. I will add dark theme when I have time.
The reason why I've created this app is because I often need to write code in front of the students when I make presentations and I think that using a tool like this decrease the possibility to make mistakes when writing.
The idea of this app came after I watch the Karen Corby presentation in MIX09 called Building Microsoft Silverlight Controls btw you can watch it here http://videos.visitmix.com/MIX09/T16F . But because I was unable to find this app I've created my own.

|
1

Real Ajax for Real Java Developers: GWT & jQUERY

Posted by JOKe on 9/02/2009 12:56:00 AM

In this days every Ajax application uses jQuery or Dojo or something like this. If you ask me jQuery is the most often framework because it is small, it helps a lot, it has cool features and it is promoted by Microsoft (we live in strange days). jQuery can be used for many things one of them is effects. We all know how Flash, Silverilght and JavaFX “Rich UI” look and often with CSS and JavaScript it’s very hard to make things that can be done in easy in flash. The jQuery helps a lot with it fade effects slideUp/slideDown and etc. I as a Java Developer I like GWT but often I use JSF too. When I use JSF I’ve always add JQuery because at certain point I’ve always  need to type some javascript and with jquery its easier. When I use GWT I’ve wanted to be able to use JQuery the same way like I’ve use it in JSF app or even better. The solution is GWTQuery or GQuery: http://code.google.com/p/gwtquery/ . From the website we can see That Gwt Query is a jQuery-like API written in GWT, which allows GWT to be used in progressive enhancement scenarios where perhaps GWT widgets are too heavyweight.

When I saw this I said: “awesome”. You can read how to get started from here http://code.google.com/p/gwtquery/wiki/GettingStarted I will not explain how to setup and use gwt query because in the wiki you will get up2date information about possible changes but the result is awesome.

Lets assume that we have a table and we want to hide it when the user clicks a button or link but with some transition effect like fade. To do this I use gwt plugin for eclipse from google  and created a simple project. My welcome-file GwtJQuery.html looks like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
<!-- above set at the top of the file will set -->
<!-- the browser's rendering engine into -->
<!-- "Quirks Mode". Replacing this declaration -->
<!-- with a "Standards Mode" doctype is supported, -->
<!-- but may lead to some differences in layout. -->

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<!-- -->
<!-- Consider inlining CSS to reduce the number of requested files -->
<!-- -->
<link type="text/css" rel="stylesheet" href="GwtJQuery.css">

<!-- -->
<!-- Any title is fine -->
<!-- -->
<title>Web Application Starter Project</title>

<!-- -->
<!-- This script loads your compiled module. -->
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
<script type="text/javascript" language="javascript" src="gwtjquery/gwtjquery.nocache.js"></script>
</head>

<!-- -->
<!-- The body can have arbitrary html, or -->
<!-- you can leave the body empty if you want -->
<!-- to create a completely dynamic UI. -->
<!-- -->
<body>

<!-- OPTIONAL: include this if you want history support -->
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

<h1>Web Application Starter Project</h1>

<table align="center" bgcolor="yellow" id="table">
<tr>
<td colspan="2" style="font-weight:bold;">Please enter your name:</td>
</tr>
<tr>
<td id="nameFieldContainer"></td>
<td id="sendButtonContainer"></td>
<td id="hideButtonContainer"></td>
</tr>
</table>
</body>
</html>



The only changes from the base project are the script tag for gwtquery,  the id for the table with value “table” and one new column with id hideButtonContainer. The new code is only this:




...
final Button hideButton=new Button("Hide");
...
RootPanel.get("hideButtonContainer").add(hideButton);
...
hideButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
hideContainer();
}
});
...
protected void hideContainer() {
$("table").css("background-color", "grey");
$("table").click(new Function() {
@Override
public boolean f(Event e) {
$(e).as(Effects).fadeOut();
return true;
}
});
}
...



We have hideButton, we add it to the RootPanel and we have clickHandler that invokes method called hideContainer. The methods uses GWTQuery which looks like jquery and what we do: we are make instant changing of the background-color to grey and fade effect on the table. You can read the getting started guide of gwt query for more info but the result looks like this:












|
14

Real Ajax for Real Java developers: GWT

Posted by JOKe on 9/02/2009 12:25:00 AM

Everyone know about GWT right ? This is Java framework for creating real rich ajax applications using the Java language and not using JavaScript. The idea is that your project have two parts : client side and server side. The server side is Java and is compiled to Java using javac and putted in the web server the client side is compiled to JavaScript using GWT Java2JavaScript compiler, the communication between server side and client side is using async call, the result is : real AJAX.

First why I call it real ajax ? The common way to make rich applications this days ( or maybe from 2005 till now) is to use non ajax web framework and use custom ajax controls that uses UpdatePanel or AjaxPanel that makes “partial rendering”.
In typical Non Ajax application (lets use ASP.net or JSF) when we submit the form or make a call using a button server creates the HTML result and send it to the browser. The browser just visualized the HTML and “voala” we have regular page. To create the view in server side is not the best idea but it was used for the last 10 years or more.

Lets create a simple ASP.net page ( I will create ASP.net page not JSF page because it is faster there is no difference in the result and the way how it is created, they are almost the same).

The ASP.net page looks like this:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>



 



When we click the button with ID Button1 we invoke some server side logic. So to invoke it we make a submit of our form and executes the action(method) it is the same like we did with Struts in 2002. Our method just changes the text in the TextBox1 LOL we can make it with JavaScript but in 2002 till 2005 no one wants to hear about JavaScript so we have :




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Voala";
}
}



when we make a submit of this page the server returns the whole new response and the browser refreshes. I will use firebug to see the response of the call it looks like this:




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE0MDM4MzYxMjNkZPJve7rYC/PGVOdFFdRTdiGKYG/K" />
</div>

<div>

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLE77ufDwLs0bLrBgKM54rGBv3Oo8jrqGGAkfJCVYhL30amEfxf" />
</div>
<div>
<input name="TextBox1" type="text" value="Voala" id="TextBox1" />
<br />
<input type="submit" name="Button1" value="Button" id="Button1" />
</div>
</form>
</body>
</html>



Wow the result was 804B just for the text Voala, maybe here some Dojo/Mojo etc developer will laugh and say just create a JavaScript function man.



In typical AJAX application using ASP.net and or JSF we have some kind of updatable panel and some JavaScript libraries that are inserted automatically from the framework and that makes the partial rendering.  To create an ASP.net AJAX application because it is simpler than JSF RichFaces application. The ASP.net AJAX page looks like this :




<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>



The idea is that when we make a request the response sended from the server is only the content of this UpdatePanel so the response is “HTML” and the JavaScript AJAX library just replaces the old content with the new content (yes it makes a lot of other things like adding listeners to components and etc.) But when we make a call the response looks like this :




189|updatePanel|UpdatePanel1|
<input name="TextBox1" type="text" value="Voala" id="TextBox1" />
<br />
<input type="submit" name="Button1" value="Button" id="Button1" />
|48|hiddenField|__VIEWSTATE|/wEPDwUINzcxOTk0MDJkZHSPHZdmYurKtHlUqe6IDY0NDG3E|56|hiddenField|__EVENTVALIDATION|/wEWAwKA97K8CgLs0bLrBgKM54rGBocZWWYZCHRaxZUGe6GQYbkXE1Wy|0|asyncPostBackControlIDs|||0|postBackControlIDs|||13|updatePanelIDs||tUpdatePanel1|0|childUpdatePanelIDs|||12|panelsToRefreshIDs||UpdatePanel1|2|asyncPostBackTimeout||90|12|formAction||Default.aspx|



Yes there is some VIEWSTATE “SHIT” that is ASP.net SHIT but you know the idea(you can see this buy yourself with firebug). The result is 584B WOW if you ask me 804B vs 584B not a big deal. The only plus is better use experience because its page doesn't blink. Anyway the RichFaces + JSF example is almost the same the result looks like this




<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><span id="j_id359:textBox1"
>Voala</span><meta name="Ajax-Update-Ids" content="j_id359:name" /><span id="ajax-view-state"
><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id2"
/></span><meta id="Ajax-Response" name="Ajax-Response" content="true" /></body></html>



The result is almost the same but there is no BIG viewstate.value. Anyway I’ve hear the term AJAH from one MAX conf so we can say that THIS IS NOT AJAX THIS IS AJAH why ? because the response is HTML so this is Asynchronous JavaScript and HTML, in typical AJAX application like the applications that we want to create we must use JSON for the response and we will want the view to be in the client and we will want to use the server as a server.



How typical ASP.net, PHP, XXX where XXX is everything developers make real AJAX? with JavaScript this will be the way how the things will be done in ASP.net 4.0 too with JavaScript client side controls that will make async calls to ASP.net methods. I can say only OMG. I don't want JavaScript because I dont like Scripting languages and because they dont have the great IDE support that we Java developers want (there is no JavaScript ide like IntelliJ IDEA right ? ). The Java community have an option that other developers dont have : GWT or Real AJax without JavaScript. The result is that we use real AJAX without JavaScript like no one else.



Real AJAX way: lets create a GWT project and add the fallowing content. This is 100% Java code no JavaScript :




public class TestGWTModule implements EntryPoint {
private Button clickMeButton;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();

final TextBox textBox=new TextBox();
clickMeButton = new Button();

rootPanel.add(textBox);
rootPanel.add(clickMeButton);

clickMeButton.setText("Click me!");
clickMeButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
textBox.setText("Voala");
}
});
}
}



And yes we can make async call if we want in the event handler. You can read how we can do that in free GWT documentation provided by google it is easy.In this code we can even use Generics and ArrayLists and almost whatever we will need, yes for example we cant use Threads but do we have Threads in javaScript ? The result is that when we invoke this code we get 0B response why ? Because it is compiled to JavaScript !



Lets make it AJAX so we will need a GWT RPC service you can read how to create one here : http://code.google.com/webtoolkit/tutorials/1.6/RPC.html When we change the clickHandler to make an Ajax call the new handler looks like this :




clickMeButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
HelloServiceAsync helloService=GWT.create(HelloService.class);
((ServiceDefTarget)helloService).setServiceEntryPoint("/hello");
helloService.sayVoala(new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
textBox.setText(result);

}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});

}
});



Maybe this looks strange to some of us ( which don't have experience with GWT) but it is not so hard and there is good IDE support which creates most of the code like the service interface, implementation and async object. Anyway the result is that the response is serialized by gwt and looks like this :




//OK[1,["Voala"],0,5]



and it is only 21B ! So yes THIS IS AJAX like it should be. I know that there is some .net projects like Script# that are kind of dead, maybe it is good time to resurrect them? Where is the community ? or Alt.net community ? Guys ? Anyone ? :)



I hope anyone have a clue what the ajax should be and what it is now I really hope to have fastest and better AJAX applications in the feature because this is how the browser must be used not like in 2005.


|

Copyright © 2009 JOKe's Blog All rights reserved. Theme based on the Theme by Laptop Geek with changes by JOKe. | Bloggerized by FalconHive.