Home Struts Struts Struts2.2.1 Tags Struts2.2.1 radio Tag Example

Ask Questions?

View Latest Questions


 
 

Struts2.2.1 radio Tag Example
Posted on: January 18, 2011 at 12:00 AM
Advertisement
The radio tag is a UI tag that render a radio button input field.

Struts2.2.1 radio Tag Example

The radio tag is a UI tag that render a radio button input field.

The following Example will shows how to implement the radio tag in the Struts2.2.1 --

First we create a JSP file named RadioTag.jsp as follows.

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Example radio Tag</title>

</head>

<body>

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

<h2>Fill Your Details.</h2>

<s:textfield name="username" key="Name"></s:textfield>

<s:radio list="#{'Male':'Male','Female':'Female'}" value="Gender"

name="list1"></s:radio>

<s:radio list="#{'Single':'Single','Married':'Married'}" value="Status"

name="list2"></s:radio>

<s:radio

list="#{'UnEmployed':'UnEmployed','Employed':'Employed',

'Self Employed':'Self Employed'}"

value="Employement" name="list3"></s:radio>

<s:submit></s:submit>

</s:form>

</body>

</html>

The Struts mapping file Struts.xml is as follows-

<?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.enable.DynamicMethodInvocation" value="false" />

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

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

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

<action name="RadioTag" class="roseindia.RadioTag" method="display">

<result name="none">/RadioTag.jsp</result>

</action>

<action name="ResultRadioTag" class="roseindia.RadioTag">

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

</action>

</package>

</struts>

Here is the result.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

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

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Example radio Tag</title>

</head>

<body>

<h1><s:property value="username"/> Your detail is here</h1>

Welcome Dear friend,<s:property value="username"/><br>

Your Gender is : <s:property value="list1"/><br>

Your Status is :<s:property value="list2"/><br>

Your are a <s:property value="list3"/> Person.

</body>

</html>

The action class RadioTag.java is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;

public class RadioTag extends ActionSupport {

private String username;

private String list1;

private String list2;

private String list3;

public String execute() throws Exception {

return SUCCESS;

}

public String getList1() {

return list1;

}

public void setList1(String list1) {

this.list1 = list1;

}

public String getList2() {

return list2;

}

public void setList2(String list2) {

this.list2 = list2;

}

public String getList3() {

return list3;

}

public void setList3(String list3) {

this.list3 = list3;

}

public String getUsername() {

return username;

}

public void setUsername(String username) {

this.username = username;

}

public String display() {

return NONE;

}

}

This Program produces output on the basis of the Radio Tag evaluation, This  give the output as-

Output:-

 

Download Select Source Code

Related Tags for Struts2.2.1 radio Tag Example:


DMCA.com