10

JavaEE 5 (JSF + JPA + EJB3) using Eclipse

Posted by JOKe on 10/26/2009 05:56:00 PM in
Today I will show you how to create Enterprise Application using Java EE 5 and GlassFish.
I will use
- Eclipse 3.5 + WTP
- GlassFish v. 2.1
- JSF Mojarra implementation.
- EJB 3.0.
- JPA Toplink essentials implementation.
- MySQL
No NetBeans or JDeveloper magic involved :)
The prerequirement is:
Add datasource in glassfish. Read this how you can make this here: http://gochev.blogspot.com/2009/10/creating-datasource-in-glassfish-v-21.html

1) First you need to add glassfish in your eclipse.
- Go to Servers View
- Right Click, New
- Choose GlassFish v 2.1 if you dont have glassfish click on Download additional adapters link choose glassfish wait and restart eclipse. Than try again.




2) Create the database

CREATE TABLE `lesson`.`USERS` (
`id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`username` VARCHAR(45) NOT NULL,
`password` VARCHAR(45) NOT NULL,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`)
)
ENGINE = InnoDB;



3) Create EJB project





4) Add persistance.xml file in META-INF folder

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">

<persistence-unit name="toursUnit">
<jta-data-source>lessonMySQL</jta-data-source>
<class>org.joke.model.User</class>
</persistence-unit>

</persistence>



5) Create Simple Entity org.joke.model.User

package org.joke.model;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "USERS")
public class User {

private Long id;
private String name;
private String username;
private String password;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Basic
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Basic
public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

@Basic
public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}



}


6) Create HelloService EJB that will use EntityManager

- The local interface is:
package org.joke.service;
import javax.ejb.Local;

import org.joke.model.User;

@Local
public interface HelloService {
public User login(String username,String password);
}


-The implementation is:

package org.joke.service;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.joke.model.User;

/**
* Session Bean implementation class HelloServiceImpl
*/
@Stateless
public class HelloServiceImpl implements HelloService {

@PersistenceContext(unitName = "toursUnit")
EntityManager em;

public HelloServiceImpl() {
}

@Override
public User login(String username, String password) {
Query query = em
.createQuery("select u from User u where u.username = :username and u.password = :password");
query.setParameter("username", username);
query.setParameter("password", password);

List<User> result = query.getResultList();

if (result != null && result.size() > 0) {
return result.get(0); //first user
}
return null;
}

}


7) Create Dynamic Web Project





8) Add JSF to this Dynamic Web Project

- Edit web.xml and add FacesServlet
 <servlet>
<display-name>FacesServlet</display-name>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>


9) I will use a very simple login form (login.jsp) and home.jsp where you will go if login is successfull.

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" version="2.1">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hello JSF Page</title>
</head>
<body>
<f:view>
<h:messages style="color:red;"></h:messages>
<h:form id="loginForm">
<table>
<tr>
<td align="right"><h:outputText value="Username: " /></td>
<td><h:inputText id="username"
value="#{userBean.currentUser.username}" required="true">
<f:validateLength maximum="10" minimum="3" />
</h:inputText></td>
<td><h:message for="username" style="color:red;" /></td>
</tr>
<tr>
<td align="right"><h:outputText value="Password: " /></td>
<td><h:inputSecret id="password"
value="#{userBean.currentUser.password}" required="true" /></td>
<td><h:message for="password" style="color:red;" /></td>
</tr>
<tr>
<td colspan="3"><h:commandButton value="login"
action="#{userBean.login}" /></td>
</tr>
</table>


</h:form>
</f:view>
</body>
</html>
</jsp:root>


- The home.jsp looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" version="2.1">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hello JSF Page</title>
</head>
<body>
<f:view>
Welcome user

</f:view>
</body>
</html>
</jsp:root>



- and faces-config.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<navigation-rule>
<from-view-id>/login.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/home.jsp</to-view-id>
</navigation-case>
</navigation-rule>

<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
<managed-bean-class>mbeans.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>


-The UserBean source is:

package mbeans;

import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.joke.model.User;
import org.joke.service.HelloService;

public class UserBean {
private User currentUser = new User();
@EJB
private HelloService helloService ;

public void setCurrentUser(User currentUser) {
this.currentUser = currentUser;
}

public User getCurrentUser() {
return currentUser;
}

public String login() {
User result = helloService.login(currentUser.getUsername(),
currentUser.getPassword());
if (result!=null) {
currentUser = result;
return "success";
}
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage("username and password not found"));
return null;
}

}

10) You can notice that I use HelloService and User model class in the Dynamic web project. To do this you have to add the service project as referenced by the web project.
- Right click on the web project and choose Properties

-Go to Build path/Projects

-Add the services project

-Now check the UserBean it should not contain any errors.
11) Create Enterprise Applicatin and add Web and EJB module to this application



12) Right click on the Enterprise Application and choose Run on server.

13) go to http://localhost:8080/HelloWeb/login.jsf and test it :)



That's all.
Note that we did not include any third party jar files in this projects. This is because GlassFish include JSF 1.2 Mojarra implementation and Toplink JPA implementation.

*Update : full source code of the example you can download from: http://dl.getdropbox.com/u/887821/HelloJavaEE5.rar

|
4

Creating DataSource in GlassFish v. 2.1

Posted by JOKe on 10/26/2009 05:06:00 PM in
I will show you how to create a DataSource in GlassFish version 2.1 because there were a lot of properties and I had a lot of problems when I've try to register datasource in glassfish for the first time.

1) You have to download JDBC driver for your database. For example I will use MySQL and I will use Connector/J driver that you can download from mysql official web site.

2) Place the JDBC driver in for example D:\glassfishv21\domains\domain1\lib\ext for example my driver is mysql-connector-java-5.0.4.jar

3) Start the domain for example domain1 (asadmin start-domain domain1)

4) go to http://localhost:4848 and login as admin. By default the username is 'admin' and the password is 'adminadmin'

5) go to Resources/JDBC/Connection Pools



-First we will create a connection pool. Click the 'NEW' button



-Than you must type:
- Name: of the connection pool for example MySQL Lessson
- Resource Type: javax.sql.ConnectionPoolDataSource
- Database Vendor: MySQL



-Press 'Next'
-On the Next step scroll down you will see a list of properties. The important for you (you must select this checkboxes) are: 'user','password','url'. If some of this is missing for example there is no 'url' if the vendor is Oracle you can add it using the Add property button.
- user : root
- password : rootpassword
- url : jdbc:mysql://localhost:3306/lesson?autoReconnect=true&characterEncoding=utf8



-When you fill this 3 properties you must press 'Save'
-Than select again your datasource and press 'Ping' to see is everything correct



You are now ready to create your DataSource that will use this connection pool.

6)go to Resources/JDBC/JDBC Resources



- Press 'New'
- Type some jndi name of the resource that you will use latter in your project(s)
- Choose PoolName to be the pool that you have just created.



Now we have DataSource that we can use from any Enterprise/Web Application.
In the next lesson I will create Java EE 5 application using JPA, EJB, JSF using eclipse and this app will use this datasource.

|

CV

Posted by JOKe on 10/26/2009 02:43:00 PM in

Who am I?

When you read some blog maybe you are wondering:
Who is this guy?
For that reason I will add my CV to my blog, I think this is enough :). You can download the PDF version from here.

|
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:












|

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