Thursday, June 24, 2010

Short Introduction GWT (Google Web ToolKit)

GWT:

In last couple of months, i am working on GWT (Google Web ToolKit). I am not great fan of this techonology because i got too many problems.

It uses well-known Remote Procedure Call (RPC) principles implemented by a generic servlet (RemoteServiceServlet), which you can specialize for your own needs. You also can use JavaScript Object Notation (JSON) as the data interchange format for your HTTP messages sent with the GWT HTTPRequest class.
Way of creating the application.
1)One way just install GWTSDK and create application by using following command
webappcreator -out projectname packagename.projectname
It creates structure similar to web applciation.
src:
--packagename.projectname.gwt.xml(This file contains information about entry point and inherited modules)
--packagename.client
--projectname.java (By default this is entry class and it runs while we run this applciation.)
--GreetingServiceAsync.java ( An interface with methods)
--GreetingService.java ( An interface which extends RemoteService)
--packagename.server
--GreetingServiceImpl (extends RemoteServiceServlet implements GreetingService )
This class overrides the methods of GreetingService
war:
--WEB-INF (with classes, lib folders and web.xml (similar to normal j2ee web application))
--projectname.html and .css
--build.xml (for detais of build.xml read ANT in detail)

In next post,I would like to discuss these files in detail
Now import this project to eclipse workspace ,build required jar (all required jar --inside bin of GWT folder or parallel to webappcreator) and run as JAVA Application (Hosted Mode)

2) Second way install plugin for GWT on eclipse. You will get 3 icons. One blue button ('g' is written on it) and other with red ('G' is written)and etc
Now just click on blue button and you got screen where you write project name and package name. (Uncheck Google App Engine for Now)
You project hasbeen created. If you want to use extra jar ,then build them.Some extra folders are created like test and test classes ,shared etc. Rest similar to above.



Problem: Less control over the client-side code of your application because it’s eventually generated by the GWT compiler.GWT provides a compiler that translates the Java code on the client side into JavaScript and DHTML.So you can use only few JAVA API's (lan and util).

Personally i got these error:
1)When i create war file, i am not able to create it properly while in normal web application i can create easily. (according to me This error is not because of GWT, but little bit tough for me..:( ) I am still with this error.
2)On changing platforms (Windows to linux and vice-versa), some functions doesn't support. So it requires extra time.

Maybe i am new of this tecgonology that's why i am getting these problem or it has.
But it creates good application where i want to use AJAX. Much dynamic site and better look can be created using this techonology.

Jar Needed for it:
gwt-dev-windows.jar or gwt-dev-linux.jar: Programming tools including the compiler. The embedded Web browser provided by GWT is platform-dependent.
gwt-user.jar: The GWT runtime.
gwt-servlet.jar: The jar to deploy on your application server with the code generated by the GWT compiler. It contains the RemoteServiceServlet.

Any suggestion or solution of problem. Plz tell me.

Thanks!!

Saturday, June 19, 2010

A basic application for iBatis use

Last month i got chance to learn some new techonologies like GWT (Google Web ToolKit) and iBatis. Firstly i would like to demonstrate application on iBatis. In upcoming posts, i would cover GWT.

I found iBatis very useful because With Ibatis I find myself getting the Job done faster, I create any POJO any set of tables, and I link them, much flixability in that field, but little extra work, building Queries and managing Maps (Little time required here). I never worked or got chance to learn hibernate.So bit difficult for me to tell that which is much better.But anyway here i developed a small application which only tells you that how you can use iBatis in your projects.

Download iBatis.jar
http://ibatis.apache.org/javadownloads.html

iBatis:

Step1: create SQLMapConfig.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">

<sqlMapConfig>
<settings useStatementNamespaces="true"/>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver" value="com.mysql.jdbc.Driver"/>
<property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost:3306/mhrddemo"/>
<property name="JDBC.Username" value="root"/>
<property name="JDBC.Password" value="mysql"/>
</dataSource>
</transactionManager>
<sqlMap resource="DataBean.xml"/>
</sqlMapConfig>

you can create property file and then use that values in this config file.

2)create another xml where you write query:
DataBean.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">

<sqlMap namespace="Contact">
<!--- Showing all data of table -->



<!--- Showing all data of table -->
<select id="getAll" resultClass="ibdeep.DataBean">
select university_id,entity_type,entity_description from entity_type
</select>

<resultMap id="result" class="ibdeep.DataBean">
<result property="university_id" column="university_id"/>
<result property="entity_type" column="entity_type"/>
<result property="entity_description" column="entity_description"/>

</resultMap>
<select id="getById" resultMap="result">
select * from entity_type where entity_type=#entity_type#
</select>


</sqlMap>

3) create a java file which has getter and setter of table fields or properties.

package ibdeep;

class DataBean
{

private String university_id;

private String entity_type;

private String entity_description;

public DataBean(){

}

public DataBean(String university_id,String entity_type,String entity_description){

this.university_id=university_id;
this.entity_type=entity_type;
this.entity_description=entity_description;

}

public String getUniversity_id(){

return university_id;

}

public void setUniversity_id(String university_id){

this.university_id=university_id;

}

public String getEntity_type(){

return entity_type;

}

public void setEntity_type(String entity_type){

this.entity_type=entity_type;

}

public String getEntity_description(){

return entity_description;

}

public void setEntity_description(String entity_description){

this.entity_description=entity_description;

}

}

Step 4): Create another java file
package ibdeep;

import com.ibatis.common.resources.Resources;

import com.ibatis.db.sqlmap.SqlMap;

import com.ibatis.sqlmap.client.*;

import java.io.Reader;

public class SqlMapManager {
private static SqlMap sqlMap = null;
static SqlMapManager smm;

public static SqlMapClient getSqlMapClient() {
try {
Reader reader = Resources
.getResourceAsReader("ibdeep/SqlMapConfig.xml");
SqlMapClient sqlMapper = SqlMapClientBuilder
.buildSqlMapClient(reader);
reader.close();

return sqlMapper;
} catch (Exception e) {
System.out.println("Map Exception");
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}


public void setSqlMap(SqlMap sqlMap) {
SqlMapManager.sqlMap = sqlMap;
}


public static SqlMap getSqlMap() {
return sqlMap;
}
}

Step 5) create properties file.you can use it.You can pass these values directly

url=jdbc:mysql://localhost:3306/mhrddemo
login=root
password=mysql

Step 6) Finally create java file which uses

package ibdeep;

import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;
import java.io.*;
import java.sql.SQLException;
import java.util.*;

class IBatisExample
{
public static void main(String[] args)
throws IOException,SQLException{
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
SqlMapClient sqlMap =
SqlMapClientBuilder.buildSqlMapClient(reader);

//Output all contacts

System.out.println("All Contacts");
List<DataBean> contacts = (List<DataBean>)
sqlMap.queryForList("Contact.getAll",null);
DataBean contact = null;
for (DataBean c : contacts) {
System.out.print(" " + c.getUniversity_id());
System.out.print(" " + c.getEntity_type());
System.out.print(" " + c.getEntity_description());
contact = c;
System.out.println("");
}
}
}

I hope it is useful.

Thursday, April 22, 2010

A Simple Apllication with DWR:

A Simple Apllication with DWR:

DWR: Direct Web Remoting-Easy Ajax for java

Link for DWR tutorial and download is:
http://directwebremoting.org/dwr/index.html

I found it very useful for my project PMS(Project Management System).
That's why I would like to demonstrate a simple application.

Just create webproject and put dwr.jar into lib.

Make changes in web.xml:
"<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>"

create dwr.xml and put following entries
"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 0.4//EN" "http://www.getahead.ltd.uk/dwr/dwr.dtd">

<dwr>
<allow>
<create creator="new" javascript="DwrDemo">
<param name="class" value="deep.DwrDemo"/>
</create>

</allow>
</dwr>"
value of class where you write your fuction which you want to call on any event.
and this javascript (Here DwrDemo) willbe created corresponding to that class.

Now we try to use it in a simple JSP page.
Add these lines in you JSP.

" <script type='text/javascript' src='dwr/engine.js'></script>
<script type='text/javascript' src='dwr/util.js'></script>
<!-- This JavaScript file is generated specifically for your application -->
<script type='text/javascript' src='dwr/interface/DwrDemo.js'></script>
<script type="text/javascript">

function demo() {
var name = DWRUtil.getValue("name");

DwrDemo.demo(name,function(val)
{
DWRUtil.setValue("first",val);
}
);
}
</script>

This javascript function calls demo() method which is inside DwrDemo method.
val is value which is returned by function demo().

<body>
<select id="name" name="name" onchange="demo();">
<option value="Deepak">Deepak</option>
<option value="Anil">Anil</option>
<option value="Akash">Akash</option>
<option value="Mayank">Mayank</option>
</select>

<input type="text" id="first"/>
</body> "

Class deep.DwrDemo is given below.
package deep;

public class DwrDemo {

public String demo(String name)
{
if(name.equals("Deepak"))
return "Hello "+name+" Pandey";
else
return "Hello "+name;
}

}

Now Run your application.

Tuesday, March 30, 2010

Project Management System

Hi,

Last time i wrote about Project Management System(PMS). URL for PMS is

http://pms.iitk.ernet.in/


Thanks!!
Deepak

Friday, March 19, 2010

Add Graphs by Using JFree Chart

Recently i want to add graphs in PMS application. There are too many ways to do this.One of them is JFree Chart.Steps for this are following..

Step1: Download Demo Application of JfreeChart demo and get library jar.

Step2: Add following lines in your code and import files which is required.

JFreeChart chart = ChartFactory.createPieChart("Pie Chart created by Deepak Pandey", pieDataset, true, true,true);
BufferedImage bi = chart.createBufferedImage(500, 500);
chart.setBackgroundPaint(new Color(173, 230, 163));
BufferedImage buf = chart.createBufferedImage(500, 500, null);
try {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(response.getOutputStream());
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(buf);
param.setQuality(0.75f, true);
encoder.encode(buf, param);

} catch (Exception e) {
System.out.println("Exception in JSP"+e);
}

Step3: Run you application

You can create this chart on a frame.
Create JFrame Object. and then add JFreeChart object and make this JFrame Object visible.

More Information of this JFreeChart,access following link
http://www.jfree.org

Thanks!!!

Tuesday, March 2, 2010

Custom tag

1)Create a class which extends BodyTagSupport or implements Tag

package deep;

import javax.servlet.jsp.tagext.BodyTagSupport;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;


public class Deepak extends BodyTagSupport {



BodyContent bodyContent;


public int doStartTag() throws JspException {

return EVAL_BODY_TAG;
OR
return SKIP_BODY;

}

public void setBodyContent(BodyContent
bodyContent) {
this.bodyContent = bodyContent;
}

public int doAfterBody() throws JspException {

return EVAL_BODY_TAG;
OR
return SKIP_BODY;

}

public int doEndTag() throws JspException {

return EVAL_PAGE;
}
}
//If It returns SKIP_PAGE,then code after the tag will not be executed ,in case of EVAL_PAGE it willbe calculated
2)Create tld(For ex:deep.tld)

3)Edit your web.xml

4)Add line in your JSP page
<%@ taglib uri="/WEB-INF/tag/name.tld" prefix="n" %>

and use tag which you defined earlier


5)Run your application

These are the steps which involved in making custom tag.Any suggestion or correction,plz leave comment.

Thanks
Deepak

Sunday, February 7, 2010

Project Management System

This system(PMS) can be used to manage projects. This includes project creation, task allocation, daily task monitoring, Gantt charts, sharing of documents, messaging and report generation.
Features
Managing project: User can add projects,view project according to enable/disable,update its detail
Monitoring task: Add task under projects,update its status etc
Managing organization:
Add,View and edit organisation.Admin user will assign project to user for an organisation.
Gantt chart: User can analyze project status by using Graphical Interface.
Managing resource: Add Member for your project.
N-level user: Every level of user can add its subordinate user.
Document sharing: Upload/download document for projects.
Reporting on demand:Report generation according to project status,user,task etc
Security:Proper authentication etc
E-mail notification: When a user is added or he assign task etc, a notification mail hasbeen sent.This mail configuration is configurable.

We are still working for features,for good graphics desgin and more user friendly,more graphics. And i request you to everyone,plz give suggession for more correction.It is an open source project and anyone can use and customize acording to their needs.

URL for this application:
http://202.141.40.218/

Thanks
Deepak