Magazine
 
Struts2 Tags

<h2>Reset Tag Example</h2>
<s:form>
<s:textfield name=”username” label=”User
Name” size=”15" maxlength=”10" />
<s:password name=”password”
label=”Password” size=”15" maxlength=”10" /
>
<s:reset value=”Reset” />
</s:form>
</body>
</html>

Output of the resetTag.jsp:

15. Select Tag (Form Tag) Example

The select tag is a UI tag that is used to render a HTML input tag of type select. Add the following code snippet into the struts.xml file.

<action name=”selectTag”
class=”net.javajazzup.weekDay”>
<result>/pages/formTags/selectTag.jsp</
result>
</action>

Create an action class with a list populated with various items as shown below:

 

weekDay.java

package net. javajazzup;
import
com.opensymphony.xwork2.ActionSupport;
import java.util.*;
public class weekDay extends ActionSupport{
private List day;
public String execute()throws Exception{
day = new ArrayList();
day.add(“Sunday”);
day.add(“Monday”);
day.add(“Tuesday”);
day.add(“Wednesday”);
day.add(“Thursday”);
day.add(“Friday”);
day.add(“Saturday”);
return SUCCESS;
}
public List getDay(){
return day;
}
}

If the user fills correct user name and password then it welcomes the user and displays the page like the following.

Create a jsp using the tag <s:select> This tag creates an HTML input tag of type select. This tag contains various parameters:

The label parameter sets the label expression used for rendering a element specific label. In our 1st case we have set it to “Select Day” The name parameter sets the name for the element. In our 1st case we have set it to
“daysname” The headerKey sets key for first item in list..
It must not be empty and wrongly specified. In both cases we have set it to:”1" The headerValue sets the Value expression for the first item in the list. In both cases we
have set it to:”— Please Select —”

selectTag.jsp

<%@ taglib prefix=”s” uri=”/struts-tags” %>
<html>
<head>
<title>Select Tag Example</title>

 
Feb 2008 | Java Jazz Up | 49
 
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