Home Struts Struts Struts2.2.1 Tags Example of autocompleter in struts2.2.1

Ask Questions?

View Latest Questions


 
 

Example of autocompleter in struts2.2.1
Posted on: January 19, 2011 at 12:00 AM
Advertisement
In this example, you will see the use of autocompleter tag of struts2.2.1.

Example of autocomplete in struts2.2.1

In this example, you will see the use of  autocomplete tag of  struts2.2.1. It is a combo box that will a display drop down suggestion lists while user enter on the text box.

 1- index.jsp

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

<html>

<head> <title>AutoComplete_TagExample</title> </head>

<body>

<h2>AutoComplete_Tag_Example</h2><hr>

<s:a href="autoCompleteAction.action">AutoComplete_TagExample</s:a>

</body>

</html>

2_ ListOfMonth.jsp

<%@ page contentType="text/html; charset=UTF-8"%>

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

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

<html>

<head><title>AutoComplete_TagExample</title><sx:head /></head>

<body><h2>AutoComplete_Tag_Example</h2><hr>

<s:form action="resultAction.action" >

<sx:autocompleter size="1" label="Month" 

list="nameMonths" name="month"></sx:autocompleter>

</action>

<s:submit align="left"> </s:submit>

</s:form></body>

</html>

3_ AutoCompleteAction.java

package roseindia.action;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class AutoCompleteAction extends ActionSupport {
private String password = "root";
private String user = "root";
private String url = "jdbc:mysql://192.168.10.13/autocompleteexample";
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
private List<String> nameMonths = new ArrayList<String>();
private String month;

public AutoCompleteAction() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
stmt = con.createStatement();
String sql = "select nameMonths from monthsName";
rs = stmt.executeQuery(sql);
while (rs.next()) {
nameMonths.add(rs.getString(1));
}

} catch (ClassNotFoundException e) {

e.printStackTrace();
}

}

public String getMonth() {
return month;
}

public void setMonth(String month) {
this.month = month;
}

public List<String> getNameMonths() {
return nameMonths;
}

public void setNameMonths(List<String> nameMonths) {
this.nameMonths = nameMonths;
}

public String execute() throws Exception {

return SUCCESS;
}

public String display() {
return NONE;
}
}

4_ OutListOfMonth.jsp

<struts>

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

<package name="roseindia" extends="struts-default">

<action name="autoCompleteAction" class="roseindia.action.AutoCompleteAction" method="display">

<result name="none">jspPages/ListOfMonth.jsp</result>

</action>

<action name="resultAction" class="roseindia.action.AutoCompleteAction">

<result name="success">jspPages/OutListOfMonth.jsp</result>

</action>

</package>

</struts>

4_ OutListOfMonth.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 

pageEncoding="ISO-8859-1"%>

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

<html>

<head><title>AutoComplete_TagExample</title></head>

<body>

<h2>AutoComplete_Tag_Example</h2><hr>

Selected Month :<s:property value="month" />

</body>

</html>

index.gif

AutocompleteBox.gif

success.gif

 

Download Select Source Code


Related Tags for Example of autocompleter in struts2.2.1:


DMCA.com