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.
Showing posts with label pms. Show all posts
Showing posts with label pms. Show all posts
Thursday, April 22, 2010
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!!!
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
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
Subscribe to:
Posts (Atom)