Home Struts Struts Struts2.2.1 Tags Struts2.2.1 UI tag example.

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 UI tag example.
Posted on: January 17, 2011 at 12:00 AM
Advertisement
In this section, you will see the use of struts UI tag.

Struts2.2.1 UI tag example.

In this tutorial, you will see the use of some UI_ tags of struts framework.

 1- index.jsp

<html>

<head><title>Struts2.2.1_UI_TagsExample</title></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>

<a href="uiTagAction.action">Example of UI Tags.</a>

</body>

</html>

2_ uiTags.jsp

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

<html>

<head><title>Struts2.2.1_UI_TagsExample</title>

<style type="text/css"> .bh{width: 146;height: 40;}</style></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>

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

<s:label name="formName" value="Student Registration Form........"/>

<s:textfield name="name" label="Name"></s:textfield>

<s:textarea name="address" label="Address" cssClass="bh"></s:textarea>

<s:password label="Password" name="password"></s:password>

<s:radio list="{'Male','Female'}" name="gender" label="Gender" ></s:radio>

<s:select list="course" name="courseName" headerKey="0"

 headerValue="Select Course" label="Course Name"></s:select>

<s:hidden name="message" value="Hello friends....." ></s:hidden>

<s:reset></s:reset> <br><s:submit></s:submit>

</s:form>

</body>

</html>

3_ UITagAction.java

package roseindia.action;

import java.util.ArrayList;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class UITagAction extends ActionSupport {

private List<String> course;

private String courseName;

private String name;

private String address;

private String password;

private String gender;

private String message;

public String getName() {

return name;

}public void setName(String name) {

this.name = name;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getGender() {

return gender;

}

public void setGender(String gender) {

this.gender = gender;

}

public String getMessage() {

return message;

}

public void setMessage(String message) {

this.message = message;

}

public String getCourseName() {

return courseName;

}

public void setCourseName(String courseName) {

this.courseName = courseName;

}

public List<String> getCourse() {

return course;

}

public void setCourse(List<String> course) {

this.course = course;

}

public UITagAction() {

course = new ArrayList<String>();

course.add("MCA");

course.add("MBA");

course.add("BCA");

course.add("BBA");

course.add("PGDM");

}

public String execute() throws Exception {

return SUCCESS; }

}

4_ struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

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

<package name="bharat" extends="struts-default" namespace="/">

<action name="uiTagAction" class="roseindia.action.UITagAction">

<result >/uitags.jsp</result>

</action>

<action name="Information" class="roseindia.action.UITagAction">

<result name="success" >/outputPage.jsp</result>

</action>

</package>

</struts>

5_ outputPage.jsp

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

<html>

<head><title>Struts2.2.1_UI_TagsExample</title></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>

<h4>Student information</h4>

Student Name : <s:property value="name"/><br/>

Student Address : <s:property value="address"/><br/>

Student Password : <s:property value="password"/><br/>

Student Gender : <s:property value="gender"/><br/>

Student Course : <s:property value="courseName"/><br/>

Hidden Message :<s:property value="message"/>

</body>

</html>

Index.gif

Uitags.gif

ValueInTags.gif

Value.gif

Download Select Source Code


Related Tags for Struts2.2.1 UI tag example.:


DMCA.com