Simple form Using ExtJs

Extjs is mainly used for UI design.Today I will create a simple form using this.And I will explain code also. So that any beginner can understand easily.

 

Ext.onReady(function(){
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';

    var bd = Ext.getBody();
    var simple = new Ext.FormPanel({
        labelWidth:  85, 
        frame:true,
        title: 'Vinay Form',
        bodyStyle:'padding:10px 10px 0',
        width: 450,
        defaults: {width: 250},
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'Customer Name',
                name: 'first',
                allowBlank:false
            },{
                fieldLabel: 'Customer Last Name',
                name: 'last'
            },{
                fieldLabel: 'Address',
                name: 'company'
            }, {
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email'
            }, new Ext.form.TimeField({
                fieldLabel: 'Time',
                name: 'time',
                minValue: '8:00am',
                maxValue: '6:00pm'
            })
        ],

        buttons: [{
            text: 'Save'
        },{
            text: 'Cancel'
        }]
    });

    simple.render(document.body);

After writing this code Form would be looking like below example
form

Ext.onReady(function(){ —– This function provides a way to make our code wait until the DOM is available, before doing anything.

Ext.QuickTips.init(); — It will display error with field in oval style.
Ext.form.Field.prototype.msgTarget = ‘side’; – Message will print on side of form field
var bd = Ext.getBody();
var simple = new Ext.FormPanel({ — Created a variable of Form panel
labelWidth: 85,
frame:true,
title: ‘Vinay Form’,
bodyStyle:’padding:10px 10px 0′, —- Setting the properties
width: 450,
defaults: {width: 250},
defaultType: ‘textfield’,

items: [{ Here we are creating the item for form.

fieldLabel: ‘Customer Name’,
name: ‘first’,
allowBlank:false
},{
fieldLabel: ‘Customer Last Name’,
name: ‘last’
},{ ……………….

Form is looking after writing this code with email validation also and combo box of time also.I hope it would clear some concept of EXT JS.UI design in ExtJs is easy.

For more detail go to www.extjs.com

pimp it

Introduction to JSR-227

JSR-227 defines a standard way for tools to implement the interactions between user interfaces and services, doing this in a way that will work for any user interface and any service technology. MVC is application design pattern in this.Primary supported by Sun+oracle. JSR 227 defines an
abstraction mechanism. We are accessing data from JavaBeans, EJB, JDO or POJO in order to reterive our view. In the world of MVC applications the View and Controller layers need to interact with the Model layer. Until this JSR came along, the developer had to learn the specific API for the technology that implemented its Model layer in order to build his View and Controller layers.
With JSR 227 there is a single standard API that works with any implementation of a Model layer – regardless of the implementing technology which can be EJB, SDO, XML, JavaBeans, etc – as well as with any implementation of View layer, such as JSP, JSF, Struts, Swing or any new technology that might pop up. This will be beneficial for two group one is Developer who design UI interface. The other group is providers of business services. For example I might be a business service provider with an innovative way to implement business service. Now all I need to do is provide a data control implementation to my business service – any tool that supports JSR-227 will be able to use my business services in a transparent way.

JSR-227 influence the future of application development :-
JSR-227 as an enabling standard for Service Oriented Architecture (SOA). The concept of SOA is that you can pick up services from anywhere and use them in your application. What JSR-227 will enable you to do is ignore the specific implementation of the service and easily bind user interfaces to this service. This helps create the needed separation between service developers and application developers.

More information you can find on
:-
1.www.oracle.com
2. http://web1.jcp.org/en/jsr/detail?id=227(JSR 227 home page)

References
http://www.oracle.com/technology/tech/java/newsletter/articles/jsr227_interview.html

pimp it

Serialization Vs Externalization

Serialization is the process of converting an object into a sequence of bits so that it can be persisted on a storage medium (such as a file, or a memory buffer) or transmitted across a network connection link. This process of serializing an object is also called deflating or marshalling an object.
The serialization mechanism has been added into the Java language for two reasons:
(1) the JavaBeans mechanism uses serialization.
(2) remote method invocation (RMI) allows you to automatically use objects located at another host in the network just like any local objects.
In order to serialize an object, you need the output stream OutputStream, which must be put into the special serialization stream called ObjectOutputStream. After that, you only need to call the method writeObject() to serialize the object and send it to the output stream. . Classes ObjectInputStream and ObjectOutputStream, which respectively implement the ObjectInput and ObjectOutput interfaces, enable entire objects to be read from or written to a stream (possibly a file). To use serialization with files, we initialize ObjectInputStream and ObjectOutputStream objects with stream objects that read from and write to files—objects of classes FileInputStream and FileOutputStream, respectively
Vinayworld class implements serializable interface.

 
Import java.io.serializable;
Class vinayworld implements Serializable {
Public String vinay_variable;
Private String vinay_add;
}

Other class would be

 
Public class vinayotherClass  {
Public static void main (String args[])
{
FileOutputStream fos=new FileOutputStream("vinay.txt");
    ObjectOutputStream oos=new ObjectOutputStream(fos);
Vinayworld vw = new vinayworld();
oos.writeobject(vw);
oos.flush();
oos.close();

In this code object of the vinayworld class is serialized into a file name vinay.txt
Serialization is a Marker interface -Marker Interface is used by java runtime engine (JVM) to identify the class for special processing.
Use serialization when you need to add data to the serialization stream that is not an object data member.

Externalization is same as Sterilization except that WriteObject() and ReadObject() method are called by JVM during sterilization an desterilization of object. One thing you can do with Externalization is that you can store extra information into object like STATIC variables and transient variables or you can add more information if you have any business need. One good example is compressing and uncompressing of data to send it through network or converting one format to other like a BMP image to JPEG or GIF format.
Externalization allows you to customize how serialization is done. By implementing externalization you are controlling what gets serialized ( and what doesnot ) as versus default serialization where all non-transient attributes get serialized.
For “fat data” classes with a large number of attributes only a few of which needs to persisted, externalization will help you reduce the size of serialized stream and the time taken to serialize the object. But there will be an overhead involved because the runtime has to call your methods to read/write objects.

Performance issue
1. Further more if you are subclassing your externalizable class you will want to invoke your superclass’s implementation. So this causes overhead while you subclass your externalizable class.
2. methods in externalizable interface are public. So any malicious program can invoke which results into lossing the prior serialized state.

Difference between serialization and externalization: When you serialize an Externalizable object, a default constructor will be called automatically; only after that will the readExternal() method be called.Use the Externalizable interface when you need complete control over your bean’s serialization (for example, when writing and reading a specific file format).

http://www.coderanch.com/t/201401/Performance/java/Serialization-Vs-Externalisation
http://en.wikipedia.org/wiki/Serialization
http://www.builderau.com.au/program/java/soa/Understand-when-to-serialize-v-externalize-objects-in-Java/0,339024620,339274531,00.htm
http://www.roseindia.net/java/java-exception/serializable-exception.shtml