DWR

DWR (DIRECT WEB REMOTING)

Introductiondwr2
DWR, or Direct Web Remoting, is a Java open source library that helps developers write web sites that include Ajax technology. It is a RPC library which makes it easy to call Java functions from JavaScript and to call JavaScript functions from Java.

dwr1
How it works?
It consists of two main parts:
• Code to allow JavaScript to retrieve data from a servlet-based web server using Ajax principles.
• A JavaScript library that makes it easier for the web site developer to dynamically update the web page with the retrieved data.
Basically, it converts the java class (which was configured in dwr.xml) to JavaScript so that we can easily access any function written on server side java at front-end side.
Why to use DWR ?
DWR has a number of features like call batching, marshalling of virtually any data-structure between Java and Javascript (including binary file uploading and downloading), exception handling, advanced CSRF protection and deep integration with several Java server-side technologies like Spring and Guice.
How to implement?
To implement DWR in your spring Application
1. You need to first download the DWR jars. (dwr.jar and apache.commons.log.jar)
2. Put these jars into your jar folder.
3. Create new configuration file (dwr.xml) at the same place where web.xml is present.
4. Define dwr.xml in web.xml file, so that jvm understand the flow of execution.

<display-name>DWREasyAjax</display-name>
<servlet>
<display-name>DWR Servlet</display-name>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.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>

 

5. Then mention which java file you want to access on your frontend and vice versa.
Ex.

<dwr>
<allow>
<create creator=”new” javascript=”HorizontalMenu”>
<param name=”class” value=”samples.HorizontalMenu” />
</create>
</allow>
</dwr>

 

6. Create your java page (Servlet page)and write whatever the business logic you want.
7. Create your front end page , and add your servlet page as js file(which you configured in your dwr.xml file)
Some important link:-
1. https://www.packtpub.com/books/content/dwr-java-ajax-user-interface-basic-elements-part-1
2. http://java-x.blogspot.in/2007/03/reverse-ajax-with-direct-web-remoting.html
3. http://www.javaworld.com/article/2071890/web-app-frameworks/ajax-made-simple-with-dwr.html
4. http://www.jitendrazaa.com/blog/java/jsp/step-by-step-dwr-application-simple-ajax-in-java/


Pushpraj Kumar
Helical IT Solution

 

Most helpful Java IDE shortcuts

Most helpful Java IDE shortcuts

This article is about one of the general aspects of programming. The article although is very small but tries to focus on one of the very important aspects that a java programmer should know. It is about the usage of keyboard. Many programmers spend a lot of time in using mouse(or track-pad) while coding. Almost 20 – 40%(based on personal experience :)) of their productive time is spent on this kind of non productive activity. The same functionality can be achieved very easily and faster by using the keyboard shortcuts. Using mouse or track-pad is non-productive as the thoughts of the developer will be distracted in search of the click action to be performed. His eyes will be distracted on to various other things. As a result the focus on problem solving will be missing.

An effective keyboard user will be more productive as using keyboard to achieve most of the functionality will be his second nature; his thoughts won’t be spent on the event to be performed to achieve the functionality. Rather he will be less prone to distraction and will spend more time on problem solving. People who have developed most of the important software that we use today don’t have the habit of using mouse(at least while programming). Mostly they are power users and probably use keyboard based editors like VI.

So, let us get familiarized with some of the popular Java IDEs and their keyboard shortcuts.

So, here is a list of most important keyboard shortcuts that a Java Developer should know. The list comprises both the most popular IDEs Eclipse and Intellij IDEA.

Action IntelliJ IDEA Eclipse
Open any file quickly Ctrl + Shift + N Ctrl + Shift + R
Find a type or class Ctrl + N Ctrl + Shift + T
Show all the members of current type Ctrl + F12 Ctrl + O
Jump to source F4 F3
To jump from one member to the next (or previous) Alt + ↓ Alt + ↑ Ctrl + Shift + ↓ Ctrl + Shift + ↑
Go to parent class Ctrl + B Ctrl + T
Back and forth through the files you have visited Ctrl + Alt + ← Ctrl + Alt + → Alt + ← Alt + →
Last edit location Ctrl + Shift + Backspace Ctrl + Q
Delete line Ctrl + Y Ctrl + D
Duplicate line Ctrl + D Ctrl + Alt + ↓
Open hierarchy Ctrl + H F4
Organize imports Ctrl + Alt + O Ctrl + Shift + O
Find next / previous F3 / Shift + F3 Ctrl + K / Shift + Ctrl + K
Debug Shift + F9 F11
Run Shift + F10 Ctrl + F11
Step Into F7 F5
Step Over F8 F6
Step Out Shift + F8 F7
Resume F9 F8
Rename in place Shift + F6 Alt + Shift + R
Format code Ctrl + Alt + L Ctrl + Shift + F
Change signature Ctrl + F6 Alt + Shift + C
Quick fix Alt + Enter Ctrl + 1
View Javadoc for member Ctrl + Q Mouse over

 

Rajasekhar

Helical IT Solutions

Installing Maven on Windows And Creating Maven project in Eclipse Juno

This blog talks about Installing Maven on Windows And Creating Maven project in Eclipse Juno

Maven is build and dependency management tool for java based application development, it is not install as windows service, rather is configured using windows environment variable.

In this post, I will summarize the steps need to install maven on windows operating system.

Step 1) Install java if not already installed

To install java download JDK installer from here and add/update JAVA_HOME variable

Go to control à system and security à system à advance system settings à advance tab à environment variables

Click on new under user variable give the variable name as JAVA_HOME and variable value path of JDK installation as shown below

Next go to system variable and select the path variable and click on edit button inset the JAVA_HOME variable created above go to end of the variable value and add ;%JAVA_HOME%\bin as shown below

Install Maven 2

Go to command line and check for class path whether is configured correctly or not.  Type the java – version as show below

Install Maven 3

It will show the version of java if class path is configured. If not shows the version repeat step 1.

 

Step 2) Maven Installation

Download Maven and extract it location where you want. Maven can be download from here.

I extracted in D:\Maven-3.2.1 you can choose your own.

Now, set MAVEN_HOME variable just you did as JAVA_HOME variable as show below

Install Maven 4

Install Maven 5

 

 

Step 3) Test for Installation

Maven installation is complete. Now lets test it for windows command prompt go to start menu and type cmd in application location search box press ENTER. Command prompt will be open and type mvn –version and hit ENTER. It will shows the version information of maven installed. If there is any error cross check the step 2.

Creating Maven Project in Eclipse

Step 1) Installing maven eclipse plug-in

Open the eclipse IDE go to Help à Eclipse Marketplace

Eclipse marketplace window will open and search tab is activated by default search for maven. All maven related plug-in will be display click and install the Maven Integration for Eclipse WTP (Juno). If it is already installed it will shows the Update as shown below.

Install Maven 6

Step 2) Creating Maven Project

To create dynamic web project with maven, navigate to the folder where you want to store the project and supply following command:

D:\Users\Java-Project\maven-project>mvn archetype:generate -DgroupId=com.helical.maven.sample -DartifactId=SampleMavenProject -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

 

What is groupId in maven ?

groupId identifies a particular project uniquely across all projects, so we should follow an naming convention. A very simple and commonly used way of doing this is to use reverse of your domain, i.e. com.helical.maven.sample

A good way of maintaining the integrity of groupId is to use the project structure. In case the project is consists of multiple modules than every module should append an identifier to the parent groupId. i.e. com.helical.maven.sample, com.helical.maven.spring, com.helical.maven.struts .. etc.

What is artifactId in maven ?

artifactId is the name of war file without version, if you are creating it by yourself you are free to took any name of your choice in lower case and without any strange symbol. But if this is a third party jar than we have to take the name of jar as suggested by it’s distribution.

What is archetype in maven ?

Archetype is a Maven project templating toolkit which tells the maven the type of project we are going to create. Archetype enables the maven to create a template project of user’s choice so that the user can get the project up and running instantly.

“archetype:generate”  generates a new project from provided archetype or update the actual project if using a partial archetype. Maven provides a number of predefined archtypes, see more details from Maven Documentation.

What is archetypeArtifactId in maven ?

While creating a new project we provide the archetypeArtifactId that informs maven about what archetype to use to create the initial structure of the project. Maven looks it up from the archetypeCatalog and works accordingly. e.g. If we want to create a simple web-app project we specify -DarchetypeArtifactId=maven-archetype-webapp.

 

Convert Maven project to support Eclipse IDE

Here we are done with creating a dynamic web project in maven, now lets make this project compatible to Eclipse IDE. To make maven project support eclipse ide navigate to project folder and supply following command :

D:\Users\Java-Project\maven-project \SampleMavenProjec>mvn eclipse:eclipse -Dwtpversion=2.0

Now import the maven project in eclipse as shown below.

Go to File import or right click import and select the Existing Maven Project click next

Install Maven 7

Browse to above created project directory and follows the steps and click on Finish.