A Web dude specialized in Java Technology. I am doing R&D on Spring BlazeDS Integration which is Java(Spring) Flex Bridge for ERP systems. However,I have experience with software development using MS .net technologies also.My favorite technologies are Java/J2EE,Web/ORM frameworks such as Struts, Spring ,JPA,Hibernate,EJB and Adobe technologies (ActionScript 3, Flex, BlazeDS).I would like to leak my knowledge with you.
Saturday, October 30, 2010
Posted by
Sanka Senevirathna0
comments
Intercommunication with flex components
Application Flow
App.mxmlàComponent .mxml
Data passing
Component àCustomEventObject à Application
Why we say loosly couple?
Component properties aren’taccessed directly by Application.Otherwose when component change some id property or something, we have to update all the refered applications.
app.mxml is the main application.GetKey.mxml is the component and GetKeyEvent.as is the custom event class that transfer the data.
There is a variable in GetKeyEvent.as and that is public as you can see.This is the one that access both GetKey.mxml component and app.mxml application.
[Bindable]
public var key:String=null;
GetKey.mxml push the data to key and app.mxml read the data from key in GetKeyEvent.as.
GetKey.mxml push the data to key
var getKeyEvent:GetKeyEvent= new GetKeyEvent("getKey",txtKey.text);
protected void doPorocess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out=response.getWriter(); ServiceLocator obj = new ServiceLocator(); out.println("Before Insert three records\n"); Long courseId1 = obj.saveCourse("Physics"); Long courseId2 = obj.saveCourse("Chemistry"); Long courseId3 = obj.saveCourse("Maths");
showCourse(obj.listCourse(),out); out.println("End of Insert three records\n\n\n\n"); obj.updateCourse(courseId3, "Mathematics"); showCourse(obj.listCourse(),out); out.println("End of update three records\n\n\n\n"); obj.deleteCourse(courseId2); out.println("End of delete chemistry records\n\n\n\n"); showCourse(obj.listCourse(),out);
/* //Following Are the code in JPA for insert query EntityManagerFactory emf=Persistence.createEntityManagerFactory("hibernate-servlet"); EntityManager em=emf.createEntityManager(); Course course = new Course(); course.setCourseName(courseName); course.setCourseId(200); Long courseId = 200L; em.persist(course); System.out.println("Afetr Save");*/
public class HibernateUtil { private static final SessionFactory sessionFactory; static { try { // sessionFactory = new Configuration().configure().buildSessionFactory();//Default configuration sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();//Annotation Configuration
Tuesday, June 1, 2010
Posted by
Sanka Senevirathna0
comments
Spring BlazeDS Integration
1. Configuring and Using the BlazeDS
MessageBroker with Spring
MessageBroker is the heart of the Spring BlazeDS Integration. When HTTP messages come from Flex client will be routed through the Spring DispatcherServlet to the Spring-managed MessageBroker.
There is no need to configure the BlazeDS MessageBrokerServlet when using the Spring-managed MessageBroker.
2. Configuring the Spring DispatcherServlet
web.xml is the heart of the j2ee web project.So we have to configure it because each an every request is map to web.xml.
The DispatcherServlet must be configured in web.xml to bootstrap a Spring WebApplicationContext. For example:
Spring MVC Dispatcher Servlet org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/config/web-application-config.xml
1
3. Configuring the MessageBroker in Spring
A simplified Spring XML config namespace is provided for configuring the MessageBroker in your WebApplicationContext. To use the namespace support you must add the schema location in your Spring XML config files. A typical config will look something like the following:
...
Following XML config namespace tags makes the Spring BlazeDS Integration configuration tags available under the flex namespace in your configuration files. The above setup will be assumed for the rest of the configuration examples to follow. For the full detail of every attribute and tag available in the
config namespace, be sure to refer to the spring-flex-1.0.xsd as every element and attribute is fully documented there. Using an XSD-aware XML editor such as the one in Eclipse should bring up the documentation automatically as you type.
At a minimum, the MessageBrokerFactoryBean must be configured as a bean in your Spring WebApplicationContext in order to bootstrap the MessageBroker, along with a MessageBrokerHandlerAdapter and an appropriate HandlerMapping (usually a SimpleUrlHandlerMapping) to route incoming requests to the Spring-managed MessageBroker.
These beans will be registered automatically by using the provided message-broker tag in your bean definition file. For example, in its simplest form:
This will set up the MessageBroker and necessary supporting infrastructure using sensible defaults. The defaults can be overriden using the provided attributes of the message-broker tag and its associated child elements. For example, the default location of the BlazeDS XML configuration file (/WEB-INF/flex/services-config.xml) can be overridden using the services-config-path attribute. The MessageBrokerFactoryBean uses Spring's ResourceLoader abstraction, so that typical Spring resource paths may be used. For example, to load the configuration from the application's classpath:
The equivalent MessageBrokerFactoryBean definition using vanilla Spring configuration would be:
Note especially that with the message-broker tag, it is not necessary to assign a custom id to the MessageBroker, and it is in fact discouraged so that you won't have to continually reference it later. The only reason you would ever need to provide a custom id is if you were bootstrapping more than one MessageBroker in the same WebApplicationContext.
Sunday, May 30, 2010
Posted by
Sanka Senevirathna0
comments
How to navigating through the Data or ArrayCollection using Flex form
I know you guys have a problem of having navigating through tha data of ArrayCollection by using the Flex Form Here is the solution for viewing data, or navigating data of Flec ArrayColletion that contain bean objects....
Tuesday, May 11, 2010
Posted by
Sanka Senevirathna0
comments
Flex Dynamically popup searchable Data-grid For Demo purpose I have create non DB version as following.Full code example is following... Check it and get idea...No need to describe this.
tt.addChild(mygrid); PopUpManager.addPopUp(tt, app, false); PopUpManager.centerPopUp(tt);//this is only set location :center mygrid.addEventListener(DataGridEvent.ITEM_EDIT_BEGINNING,clickRow); this.txt.addEventListener(DragEvent.DRAG_ENTER,fndragEnterHandler);//grag and drop facility this.txt.addEventListener(DragEvent.DRAG_OVER,fndragOverHandler);//grag and drop facility this.txt.addEventListener(DragEvent.DRAG_DROP,fndragDropHandler);//grag and drop facility
}
private function getDataGridColumns(columnsNameList:Array,columnsFilterList:Array):Array { var dataGridColumnList:Array =new Array();
for (var i:String in columnsNameList) {
//Type of Filters : MultipleChoiceFilterEditor,SliderFilterEditor,WildcardFilterEditor,NumberRangeFilter,DateRangeFilter(new one) var dgc:MDataGridColumn = new MDataGridColumn(columnsNameList[i]); if("String"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(WildcardFilterEditor);} else if("Integer"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(SliderFilterEditor); } // else if("Date"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(DateRangeFilterEditor); } dataGridColumnList.push(dgc); } return dataGridColumnList; }
private function fndragEnterHandler(event:DragEvent):void { if (event.dragSource.hasFormat("items")) DragManager.acceptDragDrop(TextInput(event.currentTarget)); }
private function fndragOverHandler(event:DragEvent):void { if (event.dragSource.hasFormat("items")) DragManager.showFeedback(DragManager.COPY); }
private function fndragDropHandler(event:DragEvent):void { event.preventDefault(); var itemsArray:Array = event.dragSource.dataForFormat("items") as Array; TextInput(event.currentTarget).text=itemsArray[0].(this.columnName); }
tt.addChild(mygrid); PopUpManager.addPopUp(tt, app, false); PopUpManager.centerPopUp(tt);//this is only set location :center mygrid.addEventListener(DataGridEvent.ITEM_EDIT_BEGINNING,clickRow); this.txt.addEventListener(DragEvent.DRAG_ENTER,fndragEnterHandler);//grag and drop facility this.txt.addEventListener(DragEvent.DRAG_OVER,fndragOverHandler);//grag and drop facility this.txt.addEventListener(DragEvent.DRAG_DROP,fndragDropHandler);//grag and drop facility
}
private function getDataGridColumns(columnsNameList:Array,columnsFilterList:Array):Array { var dataGridColumnList:Array =new Array();
for (var i:String in columnsNameList) {
//Type of Filters : MultipleChoiceFilterEditor,SliderFilterEditor,WildcardFilterEditor,NumberRangeFilter,DateRangeFilter(new one) var dgc:MDataGridColumn = new MDataGridColumn(columnsNameList[i]); if("String"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(WildcardFilterEditor);} else if("Integer"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(SliderFilterEditor); } // else if("Date"==columnsFilterList[i]){dgc.filterEditor=new ClassFactory(DateRangeFilterEditor); } dataGridColumnList.push(dgc); } return dataGridColumnList; }
private function fndragEnterHandler(event:DragEvent):void { if (event.dragSource.hasFormat("items")) DragManager.acceptDragDrop(TextInput(event.currentTarget)); }
private function fndragOverHandler(event:DragEvent):void { if (event.dragSource.hasFormat("items")) DragManager.showFeedback(DragManager.COPY); }
private function fndragDropHandler(event:DragEvent):void { event.preventDefault(); var itemsArray:Array = event.dragSource.dataForFormat("items") as Array; TextInput(event.currentTarget).text=itemsArray[0].(this.columnName); }
/** * Entity implementation class for Entity: Book * */ @Entity @NamedQuery(name="listBooks", query="SELECT b FROM Book b") public class Book implements Serializable {
@Id @Column(name="Id") private Long bookId; private String title; private Float price; private String description; private String isbn; private Integer nbOfPage; private Boolean illustrations; private static final long serialVersionUID = 1L;
public Book() { super(); } public Long getId() { return this.bookId; } public void setId(Long bookId) { this.bookId = bookId; } public String getTitle() { return this.title; } public void setTitle(String title) { this.title = title; } public Float getPrice() { return this.price; } public void setPrice(Float price) { this.price = price; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public Integer getNbOfPage() { return nbOfPage; } public void setNbOfPage(Integer nbOfPage) { this.nbOfPage = nbOfPage; } public Boolean getIllustrations() { return illustrations; } public void setIllustrations(Boolean illustrations) { this.illustrations = illustrations; }
public class AccessException implements ExceptionTranslator {
//AccessDeniedException cannot use because BlazeDS handle it. //JRException like exceptions can be handle.What have to do is throws new JRException @Override public boolean handles(Class clazz) { return (ClassUtils.isAssignable(AccessDeniedException.class,clazz)); }
@Override public MessageException translate(Throwable th) { MessageException ex =new MessageException(); ex.setCode("Application.Service"); ex.setMessage("Access Denied"); ex.setRootCause(th); return null; }
// <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>
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