Magazine
 
Struts2 Tags

Apache Struts is an open-source framework used to develop Java web applications. In this section, struts 2 form tags (UItags) will be discussed and the rest will be included in the subsequent issues of the magazine. Just download the zip file “struts2UIformtags.zip” from any link given below of each page of this article, unzip it and copy this application to the webapps directory of Tomcat. Start tomcat and write http:// localhost:8080/ truts2UIformtags/ index.jsp to the address bar. You can examine the result of each tag from this

1. Auto Completer Example

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 are 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.

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

<action name=”autocompleter”
class=”net.javajazzup.autocompleter”>
<result>/pages/formTags/
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.javajazzup;
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(“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”);
Feb 2008 | Java Jazz Up | 37
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF