Example of struts2.2.1 combobox tag.
Posted on: January 10, 2011 at 12:00 AM
In this tutorial, you will see the implementation of struts2.2.1 combobox tag.

Example of struts2.2.1 combobox tag.

In this tutorial, you will see the implementation of struts2.2.1 combobox tag. The combobox is basically an HTML INPUT of type text and HTML SELECT grouped together to give you a combo box functionality. You can place text in the INPUT control by using the SELECT control or type it in directly in the text field. 

Directory structure of combobox tag example.

 1- index.html

<html>ADS_TO_REPLACE_1

<head><title>Struts2.2.1_Combobox_Tag_Example</title>

</head>

<body>ADS_TO_REPLACE_2

<h1>Struts2.2.1_Combobox_Tag_Example</h1><hr/>

<a href="comboBoxAction">ComboBox Example</a>

</body>ADS_TO_REPLACE_3

</html>

2-comboBox.jsp

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

<html>ADS_TO_REPLACE_4

<head><title>Struts2.2.1_Combobox_Tag_Example</title>

</head>

<body><h1>Struts2.2.1_Combobox_Tag_Example</h1><hr/>ADS_TO_REPLACE_5

<b>Select Date of birth.... </b>

<s:form action="comboBoxResult.action" namespace="/">

<h4><s:combobox label="Date"ADS_TO_REPLACE_6

          headerKey="-1" headerValue="--- Select ---" list="dates"

           name="yourDate" /></h4>

<h4><s:combobox label="Month"ADS_TO_REPLACE_7

           headerKey="-1" headerValue="--- Select ---"

        list="months" name="yourMonth" /></h4>

<h4><s:combobox label="Year"ADS_TO_REPLACE_8

           headerKey="-1" headerValue="--- Select ---"

          list="years" name="yourYear" /></h4>

<s:submit value="submit" name="submit" />ADS_TO_REPLACE_9

</s:form></body>

</html>

 

3-ComboBoxAction.java

package roseindia;ADS_TO_REPLACE_10

import java.util.ArrayList;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_11

public class ComboBoxAction extends ActionSupport {

private List<String> months;

private String yourMonth;ADS_TO_REPLACE_12

private List<String> years;

private String yourYear;

private List<String> dates;ADS_TO_REPLACE_13

private String yourDate;

/*------------Month---------*/

public List<String> getMonths() {ADS_TO_REPLACE_14

return months;

}

public void setMonths(List<String> months) {ADS_TO_REPLACE_15

this.months = months;

}

public String getYourMonth() {ADS_TO_REPLACE_16

return yourMonth;

}

public void setYourMonth(String yourMonth) {ADS_TO_REPLACE_17

this.yourMonth = yourMonth;

}/*------------Date---------*/

public List<String> getDates() {ADS_TO_REPLACE_18

return dates;

}

public void setDates(List<String> dates) {ADS_TO_REPLACE_19

this.dates = dates;

}

public String getYourDate() {ADS_TO_REPLACE_20

return yourDate;

}

public void setYourDate(String yourDate) {ADS_TO_REPLACE_21

this.yourDate = yourDate;

}/*------------Year---------*/

public List<String> getYears() {ADS_TO_REPLACE_22

return years;

}

public void setYears(List<String> years) {ADS_TO_REPLACE_23

this.years = years;

}

public String getYourYear() {ADS_TO_REPLACE_24

return yourYear;

}

public void setYourYear(String yourYear) {ADS_TO_REPLACE_25

this.yourYear = yourYear;

}

public ComboBoxAction() {ADS_TO_REPLACE_26

dates = new ArrayList<String>();

for (int i = 1; i <= 31; i++) {

dates.add(" " + i);ADS_TO_REPLACE_27

}

months = new ArrayList<String>();

months.add("Jan");ADS_TO_REPLACE_28

months.add("Feb");

months.add("Mar");

months.add("Apr");ADS_TO_REPLACE_29

months.add("May");

months.add("Jun");

months.add("Jul");ADS_TO_REPLACE_30

months.add("Aug");

months.add("Sep");

months.add("Oct");ADS_TO_REPLACE_31

months.add("Nov");

months.add("Dec");

years = new ArrayList<String>();ADS_TO_REPLACE_32

for (int i = 2011; i >= 1950; i--) {

years.add("" + i);}

}ADS_TO_REPLACE_33

public String execute() {

return SUCCESS;

}ADS_TO_REPLACE_34

public String display() {

return NONE;}

}

4_struts.xml

<struts>ADS_TO_REPLACE_35

<constant name="struts.devMode" value="false" />

<package name="default" namespace="/" extends="struts-default">

<action name="comboBoxAction"ADS_TO_REPLACE_36

class="roseindia.ComboBoxAction" method="display">

<result name="none">pages/combobox.jsp</result></action>

<action name="comboBoxResult" class="roseindia.ComboBoxAction">ADS_TO_REPLACE_37

<result name="success">pages/comboBoxResult.jsp</result></action>

</package>

</struts>

5.comboBoxResult.jsp

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

<html>

<head>

<title>Struts2.2.1_Combobox_Tag_Example</title>ADS_TO_REPLACE_39

</head>

<body><h1>Struts2.2.1_Combobox_Tag_Example</h1>

<hr/><b>Date : </b><s:property value="yourDate"/>ADS_TO_REPLACE_40

<b>Month :</b><s:property value="yourMonth"/>

<b>Year :</b><s:property value="yourYear"/>

</body>ADS_TO_REPLACE_41

</html>

 

indexJsp.gif

combobox.gifADS_TO_REPLACE_42

selectValue.gif

ADS_TO_REPLACE_43

DisplayValue.gif

Download Select Source CodeADS_TO_REPLACE_44

Related Tags for Example of struts2.2.1 combobox tag.:

Advertisements

Ads

 
Advertisement null

Ads