功能說明:當選擇州別名稱時,則會出現相關之drilldown List讓您選擇。1.增加一個州別之Action(AutoCompleteState.java)內容如下:
package study;import com.opensymphony.xwork2.ActionSupport;import java.util.List;import java.util.ArrayList;public class AutoCompleteState extends ActionSupport {private List<String> state;public String execute(){state = new ArrayList();state.add("Alabama");state.add("Alaska");state.add("Arizona");state.add("Arkansas");state.add("California");state.add("Colorado");state.add("Connecticut");state.add("Delaware");state.add("District of Columbia");state.add("Florida");state.add("Georgia");state.add("Hawaii");state.add("Idaho");state.add("Illinois");state.add("Indiana");state.add("Iowa");state.add("Kansas");state.add("Kentucky");state.add("Louisiana");state.add("Maine");state.add("Maryland");state.add("Massachusetts");state.add("Michigan");state.add("Minnesota");state.add("Mississippi");state.add("Missouri");state.add("Montana");state.add("Nebraska");state.add("Nevada");state.add("New Hampshire");state.add("New Jersey");state.add("New Mexico");state.add("New York");state.add("North Carolina");state.add("North Dakota");state.add("Ohio");state.add("Oklahoma");state.add("Oregon");state.add("Pennsylvania");state.add("Rhode Island");state.add("South Carolina");state.add("South Dakota");state.add("Tennessee");state.add("Texas");state.add("Utah");state.add("Vermont");state.add("Virginia");state.add("Washington");state.add("West Virginia");state.add("Wisconsin");state.add("Wyoming");return SUCCESS;}public List<String> getState(){return state;}public void setState(List<String> state){this.state=state;}}===========================================2.增加一個呈現AutoComplete頁面(autoComplete_State.jsp)內容如下:<%@ page contentType="text/html; charset=UTF-8" %><%@ taglib prefix="s" uri="/struts-tags" %><html><head><title>Struts 2 Autocompleter Example!</title><s:head theme="ajax"/></head><body><h1>Struts 2 Autocompleter Example!</h1><s:label name="stateName" value="請選擇州別"/><s:autocompleter theme="simple" list="state" name="stateName"/></body></html>==========================================3.於struts.xml中加入一個autoComplete_State Action,內容如下:<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""http://struts.apache.org/dtds/struts-2.0.dtd"><struts><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default"><global-results><result name="error">/Error.jsp</result></global-results><global-exception-mappings><exception-mapping result="error" exception="java.lang.Exception"></exception-mapping></global-exception-mappings><action name="main" class="study.Main"><result>/index.jsp</result></action><action name="show" class="study.ShowAction"><result name="success">/show.jsp</result><result name="error">/Error.jsp</result><result name="input">/index.jsp</result></action><action name="updateForm" class="study.UpdateForm"><result>/updateForm.jsp</result></action><action name="update" class="study.UpdateSuccess"><result>/updateSuccess.jsp</result></action><action name="insertForm" class="study.InsertForm"><result>/insertForm.jsp</result></action><action name="insert" class="study.InsertSuccess"><result>/insertSuccess.jsp</result><result name="input">/insertForm.jsp</result></action><action name="delete" class="study.DeleteSuccess"><result>/deleteSuccess.jsp</result></action><action name="showDetail" class="study.UpdateForm"><result>/showDetail.jsp</result></action><action name="StudentDetailAction" class="study.UpdateForm"><result>/studentDetail.jsp</result></action><action name="autoComplete_State" class="study.AutoCompleteState"><result>/autoComplete_State.jsp</result></action></package><package name="Chart" namespace="/chart" extends="struts-default"><result-types><result-type name="chart" class="org.apache.struts2.dispatcher.ChartResult"></result-type></result-types><action name="viewModerationChart" class="study.ViewModerationChart"><result name="success" type="chart"><param name="width">400</param><param name="height">300</param></result></action><action name="viewModerationChartDispatcher"><result name="success" type="dispatcher">/ViewModerationChartDispatcher.jsp</result></action></package></struts>========================================4.測試結果:
2009年7月29日 星期三
Struts2 autocompleter功能實作
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言