博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Struts 2 Auto Completer Example
阅读量:4052 次
发布时间:2019-05-25

本文共 3692 字,大约阅读时间需要 12 分钟。

Struts 2 Auto Completer Example

 

In this section, we are going to describe the autocompleter tag. The autocompleter tag always displays a dropdown list with the options that have at least a partial match with entered text in the textbox. If the user clicks on the dropdown button then all options shown in the dropdown list. The autocompleter tag generates two input fields. First is "text", whose name is specified with the "name" attribute and another one is "hidden" whose name is "$(name). Key", where ${name} is the value in the "name" attribute.

The autocompleter tag loads its options asynchronously when the page loads suggested options based on the text entered by you in textbox. If the autoComplete attribute is set to 'true' (By defalut 'false') then it makes suggestions in the textbox. 

[Note: When we use the "simple" theme, the autocompleter can be used like the ComboBox. When used on the "ajax" theme, the list can be retrieved from an action.]

Add the following code snippet into the struts.xml file.

<action name="autocompleter" class="net.roseindia.autocompleter">
          <result>/pages/autocompleter.jsp</result>
</action>

Create a list in the action class  and populate them with various states name of U.S. as shown in the  "autocompleter" class.

package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class autocompleter extends ActionSupport{
  private List state;
  public String execute() throws Exception{
    state = new ArrayList();
    state.add("Alabama");
    state.add("Alaska");
    state.add("Arizona");
    state.add("Arkansas");
    state.add("");
    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 getState(){
    return state;
  }
}

 

<s:autocompleter theme="simple" list="state" StateName/> it creates a autocompleter list with the name of U.S. states.

autocompleter.jsp

<%taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
    <title>Struts Autocompleter Example!</title>
    <s:head theme="ajax" />
  </head>
  <body>
    <h1>Struts Autocompleter Example!</h1>
    <s:label name="stateName" value="Select State Name:" />
    <s:autocompleter theme="simple" list="state" name="StateName"/>
  </body>
</html>

Output of the autocompleter.jsp :

<s:autocompleter theme="simple" list="state" StateName/> it creates a autocompleter list with the name of U.S. states.

autocompleter.jsp

<%taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
    <title>Struts Autocompleter Example!</title>
    <s:head theme="ajax" />
  </head>
  <body>
    <h1>Struts Autocompleter Example!</h1>
    <s:label name="stateName" value="Select State Name:" />
    <s:autocompleter theme="simple" list="state" name="StateName"/>
  </body>
</html>

 

转载地址:http://yhici.baihongyu.com/

你可能感兴趣的文章
Golang 数据可视化利器 go-echarts ,实际使用
查看>>
mysql 跨机器查询,使用dblink
查看>>
mysql5.6.34 升级到mysql5.7.32
查看>>
dba 常用查询
查看>>
Oracle 异机恢复
查看>>
Oracle 12C DG 搭建(RAC-RAC/RAC-单机)
查看>>
Truncate 表之恢复
查看>>
Oracle DG failover 后恢复
查看>>
mysql 主从同步配置
查看>>
为什么很多程序员都选择跳槽?
查看>>
mongdb介绍
查看>>
mongdb在java中的应用
查看>>
区块链技术让Yotta企业云盘为行政事业服务助力
查看>>
Yotta企业云盘更好的为媒体广告业服务
查看>>
Yotta企业云盘助力科技行业创高峰
查看>>
Yotta企业云盘更好地为教育行业服务
查看>>
Yotta企业云盘怎么帮助到能源化工行业
查看>>
企业云盘如何助力商业新发展
查看>>
医疗行业运用企业云盘可以带来什么样的提升
查看>>
教育数字智能化能为现有体系带来新的起点
查看>>