Friday, July 16, 2010

Flex Framework Introduction


Flex


Introduction:

Flex is a programming language that was developed by Adobe technology. It includes all flash features.

                   Flex include two languages.

                   1). MXML

                   2). ActionScript

MXML is a tag-based language while Action Script is a flash language.

Flex coding is done with an XML based language known as MXML.
Flex codes are compiled into a file which has SWF format (Shock Wave Flash) files.
SWF files are executed with stand-alone Adobe's Flash Players.
 It  can also be directly executed in browsers that have Adobe Flash Player Plug-in installed. 


                       
How to run Flex files.

Way 1: Adobe has launched the Flex builder for developing Flex Application. We can download the Flex Builder from Adobe’s website.

Way 2: To compile Flex Application we use Apache Ant technology. Apache’s this technology is used to create a build.xml file that will be used to call the flex compiler for deploying the flex application in Eclipse IDE.

Flex languages

Flex coding involves two different languages MXML and ActionScript respectively.

1). MXML is an extended form of XML and is a tag based language, and so it is called an XML-based markup language. 

2). Flex program files end with .mxml extensions. For example your flex file such as Hello.mxml.

3). MXML used with ActionScript provide tags to separate the GUI components and is used to access the data on servers.

4).  A MXML file is converted into a SWF file that runs on a Flash Player or on a browser which has Adobe Flash Player Plug-in installed in it.

5). ActionScript a flash language is an implementation of ECMAScript  it is similar to OOP based javascript. This is the main programming tool in Adobe Flash Player. It consistes of built-in object and function. It is used to build own object and functions. Its coding is done inside the tag .

We create ActionScript files and call them inside the main MXML file with either 'source' attribute of tag or with 'include' statement inside tag by passing the relative path names of ActionScript files in these attributes. Each and every ActionScript file should be saved with '. as’ extension. 

Way 3:

          Easiest way to run Flex files.
         
          Using flex_sdk_4.1

Step 1). To download flex_sdk_4.1 from

          Step 2). To download apache-ant-1.8.1-bin

          Step 3). To unzip flex_sdk_4.1

Step 4). To unzip apache-ant-1.8.1-bin into same folder where you unzip the  flex_sdk_4.1.
          
For Example I have installed the Flex SDK

E:\InstalledSoftware\flex


Unzip apache-ant-1.8.1-bin into flex folder.



















We stored our flex file into bin folder.

For example E:\InstalledSoftware\flex\bin\Our File

Assume our file is Hello.mxml.

< ?xml version = '1.0' encoding = 'ISO-8859-1'? >
< mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml' >

< mx:Panel title = ‘Flex Framework’ color = 'green'
paddingLeft = '30' paddingRight = '30'
paddingTop = '30' paddingBottom = '30' >

< mx:Label text = ‘Flex Welcome’ / >
< /mx:Panel >
< /mx:Application >

we have to save this file into E:\InstalledSoftware\flex\bin\Hello.mxml.

Goto command prompt. Click start All Programs and Accessories and command Prompt.

























Go to E:\InstalledSoftware\flex\bin

















Use flex compiler mxmlc to compile the flex file.

Like below screen shot














Go E:\InstalledSoftware\flex\bin. And check the Hello.swf
because the mxmlc create swf file. 



















And open the Hello.swf in the browser.
 























That is all.

Best of luck.

Wednesday, July 14, 2010

Struts2 Mysql


Struts2 connect with mysql

Aim:

            In struts2, how to connect with mysql.

Procedure:

            Step 1:

                        Open mysql

            Step 2:

                        Create database such as Struts2.

                        Mysql > create database struts2;

            Step 3:

                        Mysql> use struts2;

            Step 4:

                        Create table such as student.
                       
                        Mysql > create table student (username varchar(40));

            Step 5:

                        Create project mySQLProject

            Step 6:

                        Create Action mysqlAction.java

                        Include following coding into mysqlAction.java

                       
package example;
import com.opensymphony.xwork2.ActionSupport;
import java.sql.*;
public class mysqlAction extends ActionSupport
{
    private String username;
    public String getUsername()
    {
        return username;
    }
    public void setUsername(String username)
    {
        this.username = username;
    }
    public mysqlAction()
    {
    }

    public String execute() throws Exception
    {
        Connection con=null;
        Statement stmt=null;
        ResultSet rs=null;

       
            Class.forName("com.mysql.jdbc.Driver");
            con=DriverManager.getConnection("jdbc:mysql://localhost/struts2","root","sure");
            stmt=con.createStatement();
            int i= stmt.executeUpdate("insert into student values('"+username+"')");
            if(i==0)
           
                return "failure";
          
            else
           
                return "success";
    }

}

Step 7:

            Create home.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content=”keyword” name=”struts2 mysql Example" >
< title > Home < /title >
< /head >
< body >
< s:form action="exam" method="post" >
< s:textfield label="UserName" name="username"/ >
< s:submit value="OK"/ >
< /s:form >
< /body >
< /html >

success.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content=”keyword” name=”struts2 mysql Example" >
< title > Home < /title >
< /head >
< body >
< h2 > Successfully inserted < /h2 >
< /body >
< /html >

Step 8:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >

< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="exam" class="example.mysqlAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/success.jsp < /result >
< /action >
< /package >
< /struts >

Step 9:

Add mysql-connector-java-5.1.6-bin

Right click on MySQLProject and select properties where under categories select library and select compile and click Add JAR/Folder and select where you stored mysql-connector-java-5.1.6-bin and ok.

Step 10:

Run home.jsp















you enter any values such as sureshkumar













And click ok

            The username what you have typed in textbox will be stored in database.

And success.jsp file will display if the data is stored in mysql database successfully.


 

Thursday, July 8, 2010

Struts2 Control Tag Subset with start example


Struts2 Subset Tag with start Example

Aim:
we are going to describe the subset tag. The subset tag is a generic tag that takes an iterator and outputs a subset of it. 
In this section, we are going to describe the subset tag using the start parameter. The start parameter is of integer type. It indicates the starting index (eg. first entry is 0) of entries in the source (needed to make available as the first entry in the resulting subset iterator).

           
Procedure:

Step 1:

            Create project for struts2 SubsetTagPro

Step 2:

            Create Action SubsetAction.java

            Include following coding into SubsetAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SubsetAction extends ActionSupport
{
    private List myList;
    public List getMyList()
    {
        return myList;
    }
    public void setMyList(List myList)
    {
        this.myList = myList;
    }
    public SubsetAction()
    {
    }
    public String execute() throws Exception
    {
        myList=new ArrayList();
        myList.add(new Integer(10));
        myList.add(new Integer(20));
        myList.add(new Integer(30));
        myList.add(new Integer(100));
        myList.add(new Integer(200));
        myList.add(new Integer(300));
        return "success";
    }
}

Step 3:


            Create jsp files

home.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts Subset Tag Example" >
< title > Subset Tag Example < /title >
< /head >
< body >
< s:form action="subsetAction" method="post" >
< s:submit value="GO"/ >
< /s:form >
< /body >
< /html >


SubsetAction.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Subset Example" >
< title > Struts2 Subset Example < /title >
< /head >
< body >
< s:subset source="myList" >
< s:iterator >
< s:property/ >
< /s:iterator >
< /s:subset >
< /body >
< /html >


Step 4:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >

< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="subsetAction" class="example.SubsetAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/SubsetAction.jsp < /result >
< /action >
< /package >
< /struts >


Step 5:

            Run home.jsp

Output
           



Struts2 Control Tag Subset Tag with count

Struts2 Subset Tag with count Example

Aim:

we are going to describe the subset tag. The subset tag is a generic tag that takes an iterator and outputs a subset of it.


we are going to describe the subset tag using the count parameter. The count parameter indicates the number of entries to be set in the resulting subset iterator.


Procedure:


Step 1:

Create project for struts2 SubsetTagPro


Step 2:

Create Action SubsetAction.java

Include following coding into SubsetAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SubsetAction extends ActionSupport
{
private List myList;
public List getMyList()
{
return myList;
}
public void setMyList(List myList)
{
this.myList = myList;
}
public SubsetAction()
{
}
public String execute() throws Exception
{
myList=new ArrayList();
myList.add(new Integer(10));
myList.add(new Integer(20));
myList.add(new Integer(30));
myList.add(new Integer(100));
myList.add(new Integer(200));
myList.add(new Integer(300));
return "success";
}
}

Step 3:

Create jsp files

home.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts Subset Tag Example" >
< title > Subset Tag Example < /title >
< /head >
< body >
< s:form action="subsetAction" method="post" >
< s:submit value="GO"/ >
< /s:form >
< /body >
< /html >


SubsetAction.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Subset Example" >
< title > Struts2 Subset Example < /title >
< /head >
< body >
< s:subset source="myList" count="2" >
< s:iterator >
< s:property/ >
< /s:iterator >
< /s:subset >
< /body >
< /html >


Step 4:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >

< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="subsetAction" class="example.SubsetAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/SubsetAction.jsp < /result >
< /action >
< /package >
< /struts >



Step 5:

Run home.jsp

Output

10,20 will display

Directory Structure of this project

Struts2 Control Tag Subset Tag Example


Struts2 Subset Tag Example

Aim:
we are going to describe the subset tag. The subset tag is a generic tag that takes an iterator and outputs a subset of it.
           
Procedure:

Step 1:

            Create project for struts2 SubsetTagPro

Step 2:

            Create Action SubsetAction.java

            Include following coding into SubsetAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class SubsetAction extends ActionSupport
{
    private List myList;
    public List getMyList()
    {
        return myList;
    }
    public void setMyList(List myList)
    {
        this.myList = myList;
    }
    public SubsetAction()
    {
    }
    public String execute() throws Exception
    {
        myList=new ArrayList();
        myList.add(new Integer(10));
        myList.add(new Integer(20));
        myList.add(new Integer(30));
        myList.add(new Integer(100));
        myList.add(new Integer(200));
        myList.add(new Integer(300));
        return "success";
    }
}

Step 3:

            Create jsp files

            home.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts Subset Tag Example" >
< title > Subset Tag Example < /title >
< /head >
< body >
< s:form action="subsetAction" method="post" >
< s:submit value="GO"/ >
< /s:form >
< /body >
< /html >



SubsetAction.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Subset Example" >
< title > Struts2 Subset Example < /title >
< /head >
< body >
< s:subset source="myList" >
< s:iterator >
< s:property/ >
< /s:iterator >
< /s:subset >
< /body >
< /html >


Step 4:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >

< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="subsetAction" class="example.SubsetAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/SubsetAction.jsp < /result >
< /action >
< /package >
< /struts >



Step 5:

Run home.jsp

Output










Directory Structure of this project


Struts2 Control Tag Generator Tag with id


Struts2 Generator Tag with id attribute Example

Aim:

Struts 2 generator tag is used to generate an iterator based on the “val” attribute provided in the page. The generator tag generates an iterator with "count" attribute and tag prints it out using the   tag. The separator attribute separates the val into entries of the iterator.

In this section, we are going to describe the generator tag using the id attributes. 

Procedure:

            Step 1:

            Create project GeneratorPro

            Step 2:

            Create Action GeneratorAction.java

            Include following coding into GeneratorAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;
public class GeneratorAction  extends ActionSupport
{

    public GeneratorAction()
    {
    }

    public String execute() throws Exception
    {
        return "success";
    }

}

Step 3:

            Create jsp files

            home.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Generator Tag Example" >
< title > Generator Tag Example < /title >
< /head >
< body >
< s:form action="generateAction" method="post" >
< s:submit value="OK"/ >
< /s:form >
< /body >
< /html >

GeneratorTag.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Generator Tag Example" >
< title > Generator Tag Example < /title >
< /head >
< body >
< s:generator val="%{'www.suresh.com,www.suresh.net,www.suresh.org'}" separator="," count=”3” id=”mylist” / >
< %
Iterator i=(Iterator)pageContext.getAttribute("mylist");
while(i.hasNext())
{
out.println(i.next());
}
% >
< /body >
< /html >

Step 4:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >
< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="generateAction" class="example.GeneratorAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/GeneratorTag.jsp < /result >
< /action >
< /package >
< /struts >


Step 5:

Run the home.jsp

Only three values displayed because we specify count is 3.

Directory structure of this project

Struts2 Control Tag Generator Tag with count


Struts2 Generator Tag Example

Aim:

Struts 2 generator tag is used to generate an iterator based on the “val” attribute provided in the page. The generator tag generates an iterator with "count" attribute and tag prints it out using the   tag. The separator attribute separates the val into entries of the iterator.

Procedure:

            Step 1:

            Create project GeneratorPro

            Step 2:

            Create Action GeneratorAction.java

Include following coding into GeneratorAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;
public class GeneratorAction  extends ActionSupport
{

    public GeneratorAction()
    {
    }

    public String execute() throws Exception
    {
        return "success";
    }

}

Step 3:

            Create jsp files

            home.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Generator Tag Example" >
< title > Generator Tag Example < /title >
< /head >
< body >
< s:form action="generateAction" method="post" >
< s:submit value="OK"/ >
< /s:form >
< /body >
< /html >

GeneratorTag.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< meta content="keyword" name="Struts2 Generator Tag Example" >
< title > Generator Tag Example < /title >
< /head >
< body >
< s:generator val="%{'www.suresh.com,www.suresh.net,www.suresh.org'}" separator="," count=”3” >
< s:iterator >
< s:property/ >
< /s:iterator >
< /s:generator >
< /body >
< /html >

Step 4:

Made some changes in struts.xml

< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >
< struts >

< package name="example" namespace="/example" extends="struts-default" >
< action name="generateAction" class="example.GeneratorAction" >
< result name="input" > /example/home.jsp < /result >
< result name="success" > /example/GeneratorTag.jsp < /result >
< /action >
< /package >
< /struts >


Step 5:

Run the home.jsp

Only three values displayed because we specify count is 3.

Directory structure of this project