Home Struts Struts Struts2.2.1 Tags Example of struts2.2.1 combobox tag.

Ask Questions?

View Latest Questions


 
 

Example of struts2.2.1 combobox tag.
Posted on: January 10, 2011 at 12:00 AM
Advertisement
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>

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

</head>

<body>

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

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

</body>

</html>

2-comboBox.jsp

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

<html>

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

</head>

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

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

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

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

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

           name="yourDate" /></h4>

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

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

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

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

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

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

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

</s:form></body>

</html>

 

3-ComboBoxAction.java

package roseindia;

import java.util.ArrayList;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class ComboBoxAction extends ActionSupport {

private List<String> months;

private String yourMonth;

private List<String> years;

private String yourYear;

private List<String> dates;

private String yourDate;

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

public List<String> getMonths() {

return months;

}

public void setMonths(List<String> months) {

this.months = months;

}

public String getYourMonth() {

return yourMonth;

}

public void setYourMonth(String yourMonth) {

this.yourMonth = yourMonth;

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

public List<String> getDates() {

return dates;

}

public void setDates(List<String> dates) {

this.dates = dates;

}

public String getYourDate() {

return yourDate;

}

public void setYourDate(String yourDate) {

this.yourDate = yourDate;

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

public List<String> getYears() {

return years;

}

public void setYears(List<String> years) {

this.years = years;

}

public String getYourYear() {

return yourYear;

}

public void setYourYear(String yourYear) {

this.yourYear = yourYear;

}

public ComboBoxAction() {

dates = new ArrayList<String>();

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

dates.add(" " + i);

}

months = new ArrayList<String>();

months.add("Jan");

months.add("Feb");

months.add("Mar");

months.add("Apr");

months.add("May");

months.add("Jun");

months.add("Jul");

months.add("Aug");

months.add("Sep");

months.add("Oct");

months.add("Nov");

months.add("Dec");

years = new ArrayList<String>();

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

years.add("" + i);}

}

public String execute() {

return SUCCESS;

}

public String display() {

return NONE;}

}

4_struts.xml

<struts>

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

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

<action name="comboBoxAction"

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

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

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

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

</package>

</struts>

5.comboBoxResult.jsp

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

<html>

<head>

<title>Struts2.2.1_Combobox_Tag_Example</title>

</head>

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

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

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

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

</body>

</html>

 

indexJsp.gif

combobox.gif

selectValue.gif

DisplayValue.gif

Download Select Source Code


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


DMCA.com