EJB 3.0 to Servlet then Servlet to Flex
Tuesday, January 12, 2010
EJB 3.0 and Servlet client code with MySql and Glassfish server
If you have any problem contact me sankadil@gmail.com 0713331611 in srilanka
package com.datamation.frontend.servlet;
import com.datamation.ejb.statless.EmployeDetails;
import com.datamation.ejb.statless.NewInterface;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Sanka Dilmadu Senavirathna
*/
@WebServlet(name="EmpWorkHours", urlPatterns={"/EmpWorkHours"})
public class EmpWorkHours extends HttpServlet {
@EJB
private NewInterface empInstance;
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Vector empList=empInstance.getEmpWorkHoursInfo();
out.println(empList);
out.println("<?xml version=\"1.0\"?>\n");
out.println("<catalog>");
for (int i=0; i<empList.size();i++) {
out.println("<employe employeId=\"" + ((EmployeDetails)empList.get(i)).getEmp_id()+ "\">");
out.println("<name>" + ((EmployeDetails)empList.get(i)).getEmp_name() + "</name>");
out.println("<workhours>" + ((EmployeDetails)empList.get(i)).getEmp_work_hours()+ "</workhours>");
out.println("<month>" + ((EmployeDetails)empList.get(i)).getEmp_work_month()+ "</month>");
out.println("<avgworkhours>" + ((EmployeDetails)empList.get(i)).getEmp_workHoursAvg() + "</avgworkhours>");
out.println("</employe>");
}
out.println("</catalog>");
} finally {
out.close();
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
package com.datamation.ejb.statless;
import javax.ejb.Stateless;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
@Stateless
public class Employe implements NewInterface {
private Connection CreateCon() {
Connection con = null;
try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("jdbc/mysqltest");
con = ds.getConnection();
System.out.println("Connection to tutorialApn Successfull");
} catch (NamingException e) {
e.printStackTrace();
System.out.println("Connection to tutorialApn UNSuccessfull");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Connection to tutorialApn UNSuccessfull");
}
return con;
}
private boolean CloseAll(Connection con, ResultSet rs, PreparedStatement st) {
boolean closed = true;
try {
st.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Connection not closed properly");
closed = false;
}
try {
rs.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Connection not closed properly");
closed = false;
}
try {
con.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Connection not closed properly");
closed = false;
}
return closed;
}
private boolean CloseAll(Connection con, PreparedStatement st) {
boolean closed = true;
try {
st.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("PreparedStatement not closed properly");
closed = false;
}
try {
con.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Connection not closed properly");
closed = false;
}
return closed;
}
public int setEmpInfo(EmployeDetails employeInstance) {
Connection con = CreateCon();
PreparedStatement ps = null;
int rs = 0;
try {
ps = con.prepareStatement("INSERT INTO emp_information (emp_name,emp_address_town,emp_address_street,emp_address_no) VALUES (?,?,?,?)");
ps.setString(1, employeInstance.getEmp_name());
ps.setString(2, employeInstance.getEmp_address_town());
ps.setString(3, employeInstance.getEmp_address_street());
ps.setString(4, employeInstance.getEmp_address_no());
rs = ps.executeUpdate();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
CloseAll(con,ps);
}
return rs;
}
public int setEditEmpInfo(EmployeDetails employeInstance) {
Connection con = CreateCon();
PreparedStatement ps = null;
int rs = 0;
try {
//UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value
ps = con.prepareStatement("UPDATE emp_information SET emp_name=?,emp_address_town=?,emp_address_street=?,emp_address_no=? WHERE emp_id=?");
ps.setString(1, employeInstance.getEmp_name());
ps.setString(2, employeInstance.getEmp_address_town());
ps.setString(3, employeInstance.getEmp_address_street());
ps.setString(4, employeInstance.getEmp_address_no());
ps.setInt(5, employeInstance.getEmp_id());
rs = ps.executeUpdate();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
CloseAll(con,ps);
}
return rs;
}
public Vector getEmpInfo(String key) {
Vector employeList = new Vector();
Connection con = CreateCon();
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = con.prepareStatement("SELECT emp_id,emp_name,emp_address_town,emp_address_street,emp_address_no FROM emp_information WHERE emp_name LIKE ?");
// ps.setString(1, key);
ps.setString(1, key + "%");
//ps = con.prepareStatement("SELECT emp_id,emp_name,emp_address_town,emp_address_street,emp_address_no FROM emp_information WHERE emp_name LIKE '" + key + "%'");
// ps.setString(0, key);
// WHERE emp_name LIKE '"+key+"%'
rs = ps.executeQuery();
while (rs.next()) {
EmployeDetails employeInstance = new EmployeDetails();
employeInstance.setEmp_id(rs.getInt("emp_id"));
employeInstance.setEmp_name(rs.getString("emp_name"));
employeInstance.setEmp_address_no(rs.getString("emp_address_no"));
employeInstance.setEmp_address_street(rs.getString("emp_address_street"));
employeInstance.setEmp_address_town(rs.getString("emp_address_town"));
employeList.add(employeInstance);
System.out.println("vector is : " + employeList);
System.out.println("vector size is : " + employeList.size());
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
CloseAll(con, rs, ps);
}
return employeList;
}
public Vector getEmpWorkHoursInfo() {
Vector employeList = new Vector();
Connection con = CreateCon();
PreparedStatement ps = null;
ResultSet rs = null;
try {
//SELECT * FROM `emp_workhours` WHERE 1
//SELECT emp_workhours.emp_id,MONTH , workhours, emp_information.emp_name, AVG( workhours ) AS workhoursAverage FROM emp_workhours, emp_information WHERE emp_information.emp_id = emp_workhours.emp_id
//,AVG(workhours) AS workhoursAverage
// (AVG(workhours) - workhours) AS workhoursAverage
ps = con.prepareStatement("SELECT emp_workhours.emp_id,month,workhours,emp_information.emp_name FROM emp_workhours, emp_information WHERE emp_information.emp_id=emp_workhours.emp_id");
// ps.setString(1, key);
// ps.setString(1, key + "%");
//ps = con.prepareStatement("SELECT emp_id,emp_name,emp_address_town,emp_address_street,emp_address_no FROM emp_information WHERE emp_name LIKE '" + key + "%'");
// ps.setString(0, key);
// WHERE emp_name LIKE '"+key+"%'
rs = ps.executeQuery();
while (rs.next()) {
EmployeDetails employeInstance = new EmployeDetails();
employeInstance.setEmp_id(rs.getInt("emp_id"));
employeInstance.setEmp_work_month(rs.getString("month"));
employeInstance.setEmp_work_hours(rs.getString("workhours"));
employeInstance.setEmp_name(rs.getString("emp_name"));
//employeInstance.setEmp_workHoursAvg(rs.getString("workhoursAverage"));
employeList.add(employeInstance);
System.out.println("vector is : " + employeList);
System.out.println("vector size is : " + employeList.size());
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
CloseAll(con, rs, ps);
}
return employeList;
}
public String getName() {
Connection conc = CreateCon();
PreparedStatement ps = null;
ResultSet rs = null;
String name = "";
try {
ps = conc.prepareStatement("select emp_id ,emp_name from emp_information ");
rs = ps.executeQuery();
while (rs.next()) {
name = rs.getString("emp_name");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
CloseAll(conc, rs, ps);
}
return name;
}
}
package com.datamation.ejb.statless;
import java.util.Vector;
/**
*
* @author Administrator
*/
public interface NewInterface extends EmployeLocal, EmployeRemote {
Vector getEmpInfo(String key);
int setEmpInfo(EmployeDetails employeInstance) ;
String getName();
int setEditEmpInfo(EmployeDetails employeInstance);
Vector getEmpWorkHoursInfo();
}
package com.datamation.ejb.statless;
import java.util.Vector;
import javax.ejb.Remote;
/**
*
* @author Administrator
*/
@Remote
public interface EmployeRemote {
public String getName();
public Vector getEmpInfo(String key);
public int setEmpInfo(EmployeDetails employeInstance);
public int setEditEmpInfo(EmployeDetails employeInstance);
public Vector getEmpWorkHoursInfo();
}
package com.datamation.ejb.statless;
import java.io.Serializable;
public class EmployeDetails implements Serializable {
private int emp_id =0;
private String emp_name=null;
private String emp_address_town=null;
private String emp_address_street=null;
private String emp_address_no=null;
private String emp_work_hours=null;
private String emp_work_month=null;
private String emp_workHoursAvg=null;
/**
* @return the emp_id
*/
public int getEmp_id() {
return emp_id;
}
/**
* @param emp_id the emp_id to set
*/
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}
/**
* @return the emp_name
*/
public String getEmp_name() {
return emp_name;
}
/**
* @param emp_name the emp_name to set
*/
public void setEmp_name(String emp_name) {
this.emp_name = emp_name;
}
/**
* @return the emp_address_town
*/
public String getEmp_address_town() {
return emp_address_town;
}
/**
* @param emp_address_town the emp_address_town to set
*/
public void setEmp_address_town(String emp_address_town) {
this.emp_address_town = emp_address_town;
}
/**
* @return the emp_address_street
*/
public String getEmp_address_street() {
return emp_address_street;
}
/**
* @param emp_address_street the emp_address_street to set
*/
public void setEmp_address_street(String emp_address_street) {
this.emp_address_street = emp_address_street;
}
/**
* @return the emp_address_no
*/
public String getEmp_address_no() {
return emp_address_no;
}
/**
* @param emp_address_no the emp_address_no to set
*/
public void setEmp_address_no(String emp_address_no) {
this.emp_address_no = emp_address_no;
}
/**
* @return the emp_work_hours
*/
public String getEmp_work_hours() {
return emp_work_hours;
}
/**
* @param emp_work_hours the emp_work_hours to set
*/
public void setEmp_work_hours(String emp_work_hours) {
this.emp_work_hours = emp_work_hours;
}
/**
* @return the emp_work_month
*/
public String getEmp_work_month() {
return emp_work_month;
}
/**
* @param emp_work_month the emp_work_month to set
*/
public void setEmp_work_month(String emp_work_month) {
this.emp_work_month = emp_work_month;
}
/**
* @return the emp_workHoursAvg
*/
public String getEmp_workHoursAvg() {
return emp_workHoursAvg;
}
/**
* @param emp_workHoursAvg the emp_workHoursAvg to set
*/
public void setEmp_workHoursAvg(String emp_workHoursAvg) {
this.emp_workHoursAvg = emp_workHoursAvg;
}
}
-- phpMyAdmin SQL Dump
-- version 3.0.1.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jan 13, 2010 at 05:28 AM
-- Server version: 5.1.30
-- PHP Version: 5.2.7
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `employe`
--
-- --------------------------------------------------------
--
-- Table structure for table `emp_information`
--
CREATE TABLE `emp_information` (
`emp_id` int(5) NOT NULL AUTO_INCREMENT,
`emp_name` varchar(50) NOT NULL,
`emp_address_town` varchar(50) NOT NULL,
`emp_address_street` varchar(50) NOT NULL,
`emp_address_no` varchar(10) NOT NULL DEFAULT '',
PRIMARY KEY (`emp_id`),
UNIQUE KEY `emp_name` (`emp_name`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ;
--
-- Dumping data for table `emp_information`
--
INSERT INTO `emp_information` (`emp_id`, `emp_name`, `emp_address_town`, `emp_address_street`, `emp_address_no`) VALUES
(1, 'sanka', 'a/pura', 'samagi mawatha', '1'),
(2, 'alex', 'newyork', 'maya mawatha', '2'),
(3, 'suresh', 'colombo', 'wijaya mawatha', '3'),
(4, 'saliya', 'kandy', 'wijayarama mawatha', '4'),
(5, 'samaranayaka', 'rathnapura', 'rahula mawatha', '5'),
(6, 'samarasekera', 'abilipitiya', 'anandharama mawatha', '6'),
(7, 'sakura', 'tokiyo', 'molpe', '7'),
(8, 'shrawashthi', 'jafna', '8th lane', '8'),
(9, 'anura', 'anuradhapura', '9th lane', '9'),
(10, 'abaya', 'abepussa', '1st lane', '10'),
(11, 'balasuriya', 'gampaha', '2nd lane', '11'),
(12, 'bharana', 'homagama', '3rd lane', '12'),
(13, 'bhathiya', 'siyabalapura', '4th lane', '13'),
(14, 'santhush', 'siyabalawewa', 'A1', '14'),
(15, 'kamal', 'kundasale', 'A2', '15'),
(16, 'kamani', 'katugasthota', 'A3', '16'),
(17, 'kumudu', 'kuliyapitiya', 'A5', '17'),
(18, 'kumara', 'kumana', 'A6', '18'),
(19, 'null', 'null', 'null', 'null'),
(20, '1', '1', '1', '1'),
(21, 'arjuna', '1', 'banadaranayaka mawatha', 'weyangoda'),
(22, 'sanath', 'mathara', 'uyanwaththa', '101'),
(23, 'sangakkara kumara', 'colombo 07', 'agulana mw', '154'),
(24, 'K.sangakkara', '1', 'mal renu mawatha', 'udu nuwara'),
(25, 'Arnold Swasanager', 'calfornia', 'back', '22'),
(26, 'murali', 'kandy', 'asasa mw', '1'),
(27, 'wilson', 'welinton', 'wilson wkins', '43'),
(28, 'charmara', 'hambanthota', 'nuwan mw', '34'),
(29, 'elton jhon', 'newyork', 'eminum mw', '76'),
(30, 'tom and jerry', 'losangalies', 'nikodo mw', '54'),
(31, 'JQuery', 'showtland', 'black berry', '37'),
(32, 'mihira', 'anytown', 'any', '23'),
(33, 'Jenaral SF', 'saliyapura', 'gajaba', '12'),
(34, 'jasica alba', 'newyork', 'black bery', '123');
you have to download ResizableTitleWindow.swc from internet
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="#FFFFFF"
layout="absolute"
xmlns:adobe="http://www.adobe.com/2006/fc">
<mx:HTTPService id="httpXmlDataService"
url="http://localhost:8080/EmpEntApp-war/EmployeView"
resultFormat="e4x"
result="resultHandler(event)"
fault="faultHandler(event)"
useProxy="false">
<mx:request>
<first>{first.text}</first>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="httpDataServiceInsert"
url="http://localhost:8080/EmpEntApp-war/EmployeCreate"
resultFormat="e4x"
result="resultHandler(event)"
fault="faultHandler(event)"
useProxy="false">
<mx:request>
<name>{name1.text}</name>
<!--<address>{address.text}</address>-->
<no>{no.text}</no>
<street>{street.text}</street>
<town>{town.text}</town>
</mx:request>
</mx:HTTPService>
<mx:HTTPService id="httpDataServiceEdit"
url="http://localhost:8080/EmpEntApp-war/EmployeEdit"
resultFormat="e4x"
result="resultHandler(event)"
fault="faultHandler(event)"
useProxy="false">
<mx:request>
<nameEdit>{nameEdit.text}</nameEdit>
<noEdit>{noEdit.text}</noEdit>
<streetEdit>{streetEdit.text}</streetEdit>
<townEdit>{townEdit.text}</townEdit>
<employeIdEdit>{employeIdEdit.text}</employeIdEdit>
</mx:request>
</mx:HTTPService>
<mx:ApplicationControlBar dock="true">
<mx:Label text="Background Color:"/>
<mx:ColorPicker id="colorPicker"
creationComplete="colorPicker_creationComplete(event)"
change="colorPicker_change(event)"/>
<mx:Button id="cmdViewTEmpitleWindow"
label="Employe Details"
click="titleWindow_open()"/>
</mx:ApplicationControlBar>
<adobe:ResizableTitleWindow id="empView"
x="134"
y="39"
showEffect="true"
addedEffect="zoomEmpAnimation"
height="335"
width="750">
<mx:ApplicationControlBar horizontalAlign="left"
width="250">
<mx:Button id="viewCmd"
label="switch view"
width="120"
click="changeView()"
x="500"/>
<mx:TextInput width="100"
id="first"
enter="retrive_data();"/>
</mx:ApplicationControlBar>
<mx:ViewStack id="viewstack1"
width="700"
height="250"
x="0"
y="41">
<mx:Canvas label="gride"
width="100%"
height="100%"
showEffect="{showEffect}"
id="gride">
<!-- this is the Rotate animation code addedEffect="down" -->
<mx:DataGrid showEffect="true"
addedEffect="down"
x="9"
width="682"
height="220"
editable="true"
headerHeight="20"
dataProvider="{xmldata.employe}"
y="4">
<mx:columns>
<!--<mx:DataGridColumn headerText="ID"
dataField="@employeId"
id="employeId"
width="75"/>-->
<mx:DataGridColumn headerText="Name"
dataField="name"
editable="false"/>
<mx:DataGridColumn headerText="No"
labelFunction="displayAddressNo"
editable="true"
width="75"/>
<mx:DataGridColumn headerText="Street"
labelFunction="displayAddressStreet"
editable="true"/>
<mx:DataGridColumn headerText="Town"
labelFunction="displayAddressTown"
editable="true"/>
<mx:DataGridColumn headerText="Address"
width="200"
labelFunction="displayFullAddress"
editable="true"/>
<!--<mx:DataGridColumn headerText="URL" itemRenderer="urlRenderer"/>
<mx:DataGridColumn headerText="URL" itemEditor="{inlineEditor}" editorDataField="@employeId" dataField="@employeId"/>-->
<mx:DataGridColumn dataField="@employeId"
width="50"
editable="false"
headerText="Edit">
<mx:itemRenderer>
<mx:Component>
<mx:LinkButton click="handleClick();"
label="{data.@employeId}">
<mx:Script>
<![CDATA[
import mx.controls.Text;
import mx.controls.Alert;
import flash.profiler.showRedrawRegions;
import mx.core.Container;
import mx.core.Application;
import mx.events.CloseEvent;
public function handleClick():void
{
Alert.yesLabel="Edit";
Alert.noLabel="Back";
Alert.show("Do you want to edit details of\n Mr:" + data.name + "\n employe id :" + data.@employeId, "Employe Information", Alert.YES | Alert.NO, null, handleAlert, null, Alert.YES);
}
public function handleAlert(event:Object):void
{
if (event.detail == Alert.YES)
{
Application.application.viewstack1.selectedIndex=2;
//Alert.show("Name : "+data.name+"\nAddress : "+data.address.no+data.address.street+data.address.town+"\nEmploye ID : "+data.@employeId);
Application.application.nameEdit.text=data.name;
//Alert.show("acheived... Application.application.name1.text=data.name;");
Application.application.streetEdit.text=data.address.street;
Application.application.townEdit.text=data.address.town;
Application.application.noEdit.text=data.address.no;
Application.application.employeIdEdit.text=data.@employeId;
//Alert.show("changeView acheived...");
// YES button was clicked
}
else if (event.detail == Alert.NO)
{
// NO button was clicked
}
}
]]>
</mx:Script>
</mx:LinkButton>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<!-- //navigateToURL(new URLRequest(data.url))
<mx:LinkButton textAlign="center"
label="Edit"
click="{navigateToURL(new URLRequest('http://localhost:8080/EmpEntApp-war/EmployeView?first='+xmldata.employe.@employeId));}"/>
//click="navigateToURL(new URLRequest('http://localhost:8080/EmpEntApp-war/EmployeView?first='+data.@employeId))"
-->
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
<mx:Canvas label="detail"
width="100%"
height="100%"
showEffect="{showEffect}"
id="detail">
<mx:Form x="8"
y="4"
label="Create Employe Profile"
width="300">
<mx:FormItem label="Name:">
<mx:TextInput id="name1"
width="100"/>
</mx:FormItem>
<mx:FormItem label="No:">
<mx:TextInput id="no"
width="100"/>
</mx:FormItem>
<mx:FormItem label="Street">
<mx:TextInput id="street"
width="100"/>
</mx:FormItem>
<mx:FormItem label="Town">
<mx:TextInput id="town"
width="100"/>
</mx:FormItem>
<mx:FormItem>
<mx:TextInput visible="true"
editable="false"
id="employeId"
width="100"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Create"
width="100"
id="submitCmd"
click="sendToServer();"/>
</mx:FormItem>
</mx:Form>
</mx:Canvas>
<mx:Canvas label="Edit"
width="100%"
height="100%"
showEffect="{showEffect}"
id="detailEdit">
<mx:Form x="8"
y="4"
label="Edit Employe Profile"
width="300">
<mx:FormItem label="Name:">
<mx:TextInput id="nameEdit"
width="100"/>
</mx:FormItem>
<mx:FormItem label="No:">
<mx:TextInput id="noEdit"
width="100"/>
</mx:FormItem>
<mx:FormItem label="Street">
<mx:TextInput id="streetEdit"
width="100"/>
</mx:FormItem>
<mx:FormItem label="Town">
<mx:TextInput id="townEdit"
width="100"/>
</mx:FormItem>
<mx:FormItem label="Employe ID">
<mx:TextInput visible="true"
editable="false"
id="employeIdEdit"
width="100"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button label="Save"
width="100"
id="submitCmdEdit"
click="sendEditToServer();"/>
</mx:FormItem>
</mx:Form>
</mx:Canvas>
</mx:ViewStack>
<mx:Image id="animateImage"
visible="false"
includeInLayout="false"/>
</adobe:ResizableTitleWindow>
<adobe:ResizableTitleWindow id="graphView"
x="736"
y="284"
showEffect="true"
addedEffect="zoomEmpAnimation"
height="235"
width="250">
<mx:Script>
<![CDATA[
import mx.charts.*;
import mx.controls.Alert;
import mx.charts.series.items.*;
import mx.graphics.*;
import mx.collections.ArrayCollection;
[Bindable]
public var expensesAC:ArrayCollection=new ArrayCollection([{Month: "January", Profit: 2000, Expenses: 1500, Amount: 195}, {Month: "February", Profit: 1000, Expenses: 200, Amount: 160}, {Month: "March", Profit: 800, Expenses: 500, Amount: 230}, {Month: "April", Profit: 500, Expenses: 300, Amount: 150}, {Month: "May", Profit: 700, Expenses: 450, Amount: 210}, {Month: "June", Profit: 900, Expenses: 500, Amount: 179}]);
[Bindable]
private var expensesAC1:ArrayCollection=new ArrayCollection([{Month: "Jan", Profit: 2000, Expenses: 1500, Amount: 450}, {Month: "May", Profit: 2400, Expenses: 1575, Amount: 500}, {Month: "April", Profit: 1500, Expenses: 1300, Amount: 350}, {Month: "May", Profit: 1700, Expenses: 1450, Amount: 260}, {Month: "June", Profit: 1900, Expenses: 1200, Amount: 399}]);
private function labelFunc(v:BarSeriesItem, index:int):String
{
return BarSeries(v.element).displayName + ":" + v.xNumber;
}
]]>
</mx:Script>
<mx:Panel title="Bar chart showing per item labels"
width="100%"
height="100%"
layout="horizontal">
<mx:BarChart id="Barchartold"
height="100%"
width="100%"
paddingLeft="5"
paddingRight="5"
showDataTips="true"
dataProvider="{expensesAC}">
<mx:verticalAxis>
<mx:CategoryAxis categoryField="Month"/>
</mx:verticalAxis>
<mx:series>
<mx:BarSeries id="profitseries1"
xField="Profit"
displayName="Profit"
labelPosition="inside"
labelFunction="labelFunc"/>
<mx:BarSeries id="expenseseries1"
xField="Expenses"
displayName="Expenses"
labelPosition="inside"
labelFunction="labelFunc"/>
<mx:BarSeries id="amountseries1"
xField="Amount"
displayName="Amount"
labelPosition="inside"
labelFunction="labelFunc"/>
</mx:series>
</mx:BarChart>
<mx:BarChart id="Barchartout"
height="100%"
width="100%"
paddingLeft="5"
paddingRight="5"
showDataTips="true"
dataProvider="{expensesAC}">
<mx:verticalAxis>
<mx:CategoryAxis categoryField="Month"/>
</mx:verticalAxis>
<mx:series>
<mx:BarSeries id="profitseries2"
xField="Profit"
displayName="Profit"
labelPosition="outside"
labelFunction="labelFunc"/>
<mx:BarSeries id="expenseseries2"
xField="Expenses"
displayName="Expenses"
labelPosition="outside"
labelFunction="labelFunc"/>
<mx:BarSeries id="amountseries2"
xField="Amount"
displayName="Amount"
labelPosition="outside"
labelFunction="labelFunc"/>
</mx:series>
</mx:BarChart>
</mx:Panel>
</adobe:ResizableTitleWindow>
<mx:Style source="my.css"/>
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.*;
import mx.controls.Alert;
import mx.events.ColorPickerEvent;
import mx.events.CloseEvent;
import mx.controls.Button;
import mx.managers.PopUpManager;
import mx.managers.PopUpManager;
import mx.containers.TitleWindow;
import flash.geom.Point;
[Bindable]
public var xmldata:XML;
private function sendToServer():void
{
insert_data();
changeView();
retrive_data();
retrive_data();
}
private function sendEditToServer():void
{
edit_data();
viewstack1.selectedIndex=0;
retrive_data();
retrive_data();
}
private function displayAddressNo(row:Object, column:DataGridColumn):String
{
return row.address.no;
}
private function displayAddressTown(row:Object, column:DataGridColumn):String
{
return row.address.town;
}
private function displayAddressStreet(row:Object, column:DataGridColumn):String
{
return row.address.street;
}
private function displayFullAddress(row:Object, column:DataGridColumn):String
{
return row.address.no + "," + row.address.street + "," + row.address.town;
}
public function changeView():void
{
animate();
//viewstack1.selectedIndex=0
if (viewstack1.selectedChild == detail)
{
viewstack1.selectedChild=gride;
//viewCmd.label="Detail View";
first.visible=true;
//set to insert mode,create all as empty fields
//mode.text="insert";
//name1.text="";
//no.text="";
//town.text="";
//street.text="";
//employeId.text="";
}
else if (viewstack1.selectedChild == detailEdit)
{
viewstack1.selectedChild=gride;
}
else
{
viewstack1.selectedChild=detail;
//viewCmd.label="Gride view";
first.visible=false;
}
}
private function retrive_data():void
{
httpXmlDataService.send();
}
private function insert_data():void
{
httpDataServiceInsert.send();
}
private function edit_data():void
{
httpDataServiceEdit.send();
}
private function faultHandler(event:FaultEvent):void
{
mx.controls.Alert.show(event.fault.message, "Error in getting result");
}
private function resultHandler(event:ResultEvent):void
{
xmldata=event.result as XML;
}
private function titleWindow_close():void
{
PopUpManager.removePopUp(this);
}
private function titleWindow_open():void
{
PopUpManager.addPopUp(empView, this, false); //false--true is lock background
PopUpManager.centerPopUp(empView);
//animation effect code
//customMove.end();
//customMove.play();
//animation effect code
//animation effect code
//zoomEmpAnimation.play();
//blurAnimation.play();
//over.play();
//animation effect code
}
private function colorPicker_creationComplete(evt:Event):void
{
colorPicker.selectedColor=Application.application.getStyle("backgroundColor");
}
private function colorPicker_change(evt:ColorPickerEvent):void
{
Application.application.setStyle("backgroundColor", colorPicker.selectedColor);
}
]]>
</mx:Script>
<mx:Parallel id="customMove"
target="{empView}">
<mx:Move duration="1000"
xTo="{(stage.width - empView.width) / 2}"
yTo="{(stage.height - empView.height) / 2}"/>
<mx:WipeRight duration="1000"/>
</mx:Parallel>
<mx:Parallel id="zoomEmpAnimation"
target="{empView}">
<mx:Zoom id="zoomEmp"
duration="500"
zoomHeightFrom="0.01"
zoomHeightTo="1.0"
zoomWidthFrom="0.01"
zoomWidthTo="1.0"/>
</mx:Parallel>
<mx:Dissolve alphaFrom="1.0"
alphaTo="0.1"
color="#ffff00"/>
<mx:Blur id="blurAnimation"
duration="300"
blurYFrom="1.0"
blurYTo="20.0"/>
<mx:Parallel id="over">
<mx:Zoom duration="100"
zoomHeightTo="1.3"
zoomWidthTo="1.3"/>
<mx:Blur duration="1000"/>
</mx:Parallel>
<mx:Rotate id="down"
angleFrom="0"
angleTo="360"
duration="1500"/>
<mx:Zoom id="out"
duration="200"
zoomHeightTo="1"
zoomWidthTo="1"/>
<mx:Script>
<![CDATA[
import mx.effects.easing.Exponential;
import mx.graphics.ImageSnapshot;
private function animate():void
{
animateImage.width=viewstack1.width;
animateImage.height=viewstack1.height;
animateImage.source=new Bitmap(ImageSnapshot.captureBitmapData(viewstack1));
animateImage.visible=true;
animateImage.includeInLayout=true;
switch ("down")
{
case "up":
contentMove.xFrom=0;
contentMove.xTo=0;
contentMove.yFrom=viewstack1.height;
contentMove.yTo=0;
imageMove.xFrom=0;
imageMove.xTo=0;
imageMove.yFrom=0;
imageMove.yTo=-viewstack1.height;
break;
case "down":
contentMove.xFrom=0;
contentMove.xTo=0;
contentMove.yFrom=-viewstack1.height;
contentMove.yTo=0;
imageMove.xFrom=0;
imageMove.xTo=0;
imageMove.yFrom=0;
imageMove.yTo=viewstack1.height;
break;
case "left":
contentMove.xFrom=viewstack1.width;
contentMove.xTo=0;
contentMove.yFrom=0;
contentMove.yTo=0;
imageMove.xFrom=0;
imageMove.xTo=-viewstack1.width;
imageMove.yFrom=0;
imageMove.yTo=0;
break;
default: //right
contentMove.xFrom=-viewstack1.width;
contentMove.xTo=0;
contentMove.yFrom=41;
contentMove.yTo=41;
imageMove.xFrom=0;
imageMove.xTo=viewstack1.width;
imageMove.yFrom=41;
imageMove.yTo=41;
break;
}
// toggleVisibility();
}
private function toggleVisibility():void
{
viewstack1.selectedIndex=(viewstack1.selectedIndex + 1) % viewstack1.numChildren;
contentMove.target=viewstack1.selectedChild;
}
]]>
</mx:Script>
<mx:Parallel id="showEffect">
<mx:Move id="contentMove"/>
<mx:Move id="imageMove"
target="{animateImage}"/>
<mx:effectEnd>
<![CDATA[
animateImage.visible=false;
animateImage.includeInLayout=false;
]]>
</mx:effectEnd>
</mx:Parallel>
<mx:Style>
Alert {
modalTransparencyBlur: 5;
modalTransparency: 0.6;
modalTransparencyColor:#ffffff;
modalTransparencyDuration: 300;
}
</mx:Style>
</mx:Application>