Showing posts with label UI tags III. Show all posts
Showing posts with label UI tags III. Show all posts

Tuesday, June 15, 2010

Struts2-UI Tags-III


Struts2-UI-TAGS-II

Aim:
            We will examine the textarea and doubleselect and file UI Tags.

Procedure:

Step 1:

            Create project for struts2.

Step 2:
           
            Create Action class

Step 3:

            Made some changes in struts.xml

Step 4:

            Create home.jsp and display.jsp file

Step 5:

            Run the home.jsp file
Step 1:

            Create project name as UI-tag III


Open the netbean 6.8

File—New Project New Project window will open.

Select java web under categories and select web Application under Projects.

Next

New Web Application window will open.

Give project name ( UI-Tags-III)
Next and also Next

Select Framework

You select struts2

Finish

The project UI-Tags-III has created successfully.


NOTE:

Delete all files under example folder for web pages and source packages

Structure of the Struts2 Project



       














     Store all jsp files under web pages

    Store all action class under sources packages


Step 2:

Create Action class name as uiaction

Right click on example under Source Packages

New—Other—select Struts2 under categories and select Struts2 Action under File types.

Next

Give Action class name (uiaction)

Finish

The Action class uiaction has created successfully.
 
Include following coding into uiaction

package example;
import java.util.*;

import com.opensymphony.xwork2.ActionSupport;
public class UIAction extends ActionSupport
{
    private String address;

    private String dishes;

    public String getDishes() {
        return dishes;
    }

    public void setDishes(String dishes) {
        this.dishes = dishes;
    }

    public String getAddress()
    {
        return address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

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

}

Step 3:

            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="uiaction" class="example.uiaction" >
< result name="success" > /example/display.jsp < /result >
< result name="input" > /example/home.jsp < /result >
< /action >

< /package >
< /struts >

Step 4:

Create home.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >

< title & gt JSP Page < /title >

< /head >
< body >
< s:form action="uiaction" method="post" >
< s:file label="browse" accept="text/*"/ >
< s:textarea label="Address" name="address" cols="15" rows="5"/ >

< s:doubleselect label="Select Item"
headerValue="--- Please Select ---"
headerKey="1" list="{'Color','Fruits'}"
doubleName="dishes"
doubleList="top == 'Color' ? {'Black','Green','White',
'Yellow','Red','Pink'} : { 'Apple','Banana','Grapes','Mango'}" / >
< s:submit/ >
< /s:form >
< /body >
< /html >

Create display.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > JSP Page < /title >
< /head >
< body >

< s:property value="address" / >

< s:property value="dishes"/ >

< s:property value="file1"/ >

< /body >
< /html >


Step 5:

Run the display.jsp

Output