Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Struts
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Radio Tag <html:radio>:

                         

html:radio Tag - This Tag renders an HTML <input> element of type radio, populated from the specified property of the bean associated with  our current form.

Note : This tag is only valid when nested inside a form tag body.

 

 

 

 

 

Name Description
disabled The disabled attribute set to true if this input field should be disabled.
name The attribute name of the bean whose properties are consulted when rendering the current value of this input field. If not specified, the bean associated with the form tag we are nested within is utilized
property The corresponding bean property for this radio tag.
value The value of the radio tag.

Example Illustrating the use of the Radio<html:radio> tag.
Here you will learn to use the Struts Html <html:radio> tag. 
We will cover an example that will show a working of<html:radio> tag.

Example code :
Creating Form Bean
Develop a simple Form Bean  class RadioTagActionForm.java

package ActionForm;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class RadioTagActionForm extends 
org.apache.struts.action.ActionForm{

      
    
    private String indian;
    
    private String american;
    
    public String getIndian() {
        return indian;
    }
    
    public void setIndian(String string) {
        indian = string;
    }
    public String getAmerican() {
        return american;
    }
    
    public void setAmerican(String string) {
        american = string;
    }
    
    public RadioTagActionForm() {
        super();
        
    }

}

Creating an Action Class :

Develop a simple action class RadioTagAction .java.


package action;

import ActionForm.RadioTagActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class RadioTagAction extends Action {
       
 private final static String SUCCESS = "success";
        
 public ActionForward execute(ActionMapping mapping, ActionForm  form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
                
      if(form!=null){
                
 RadioTagActionForm radiaTagActionForm=(RadioTagActionForm)form;
 System.out.println("radiaTagActionForm"
+radiaTagActionForm.getAmerican
());
     }        
      return mapping.findForward(SUCCESS);
        
    }
}

Defining form Bean in struts-config.xml file :
Add the following entry in the struts-config.xml file for defining the form bean .
<form-bean name="RadioTagActionForm" type="ActionForm.RadioTagActionForm"/>

Developing the Action Mapping in the struts-config.xml
Here, Action mapping helps to select the Form Bean, Action Class etc, specific requests.

<action input="/" name="RadioTagActionForm" path="/RadioTagAction" 
    
scope="request" type="action.RadioTagAction" validate="false">

<forward name="success" path="/redioTagOutPut.jsp"/> 

</action>

Developing the RadioTag.jsp page :
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>RadioTag</title>
        <font color="#FFFF33">Plz select Option for Demo  ---></font>s
    </head>
     <body bgcolor="#999933">       
        <h3><font color="#FFFF33">RadioTag</font></h3>        
        <html:form action="/RadioTagAction">            
            <h3>Indian</h3><html:radio name="RadioTagActionForm" 
                      
property="indian" value="Indian"  disabled="false"/>
            <h3>American</h3><html:radio name="RadioTagActionForm" 
                      property=
"american" value="American" disabled="false"/>
            <html:submit/>
        </html:form>
        
    </body>
</html>
 

Developing the redioTagOutPut.jsp page :
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><font color="#FFFF33">OUT PUT</font></title>
    </head>
     <a href="RadioTag.jsp">Go Back.........</a><br/>   
    <body bgcolor="#999933">
        
        <h3><font color="#FFFF33">OUT PUT</font></h3>   
        <h3><font color="#FFFF33">Selected Value is.......</font></h3>
        <bean:write name="RadioTagActionForm" property="indian"/>
        <bean:write name="RadioTagActionForm" property="american"/>
        
    </body>
</html>

Add the following line in the index.jsp to call the form.
<a href="RadioTag.jsp">RadioTagDemo</a><br/> 

Building and Testing the Example  :
Build and deploy and Test  the application . Open the browser and navigate to the RadioTag.jsp page. 
Your browser displays the following page.

Don't select  option  on the RadioTag.jsp  page, and see the output.

Output:

Now select the option on  the RadioTag.jsp ,

Output:

Above demo  Displays the working of<html:radio>tag.

                         
Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.