Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Radio Tag (Form Tag) Example 
 

In this section, we are going to describe the radio tag .

 

Radio Tag (Form Tag) Example

                         

In this section, we are going to describe the radio tag. The radio tag is a UI tag that renders a radio button input field.

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

<action name="radioTag" class="net.roseindia.checkboxlistTag">
        <result>/pages/uiTags/radioTag.jsp</result>
</action>

Create an action class with two lists as shown below:
checkboxlistTag.java

package net.roseindia;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;

public class checkboxlistTag extends ActionSupport{
  
  private List fruits;
  private List animals;  
  public String execute()throws Exception{
    fruits = new ArrayList();
    fruits.add("Apple");
    fruits.add("Mango");
    fruits.add("Orange");
    fruits.add("Pine Apple");

    animals = new ArrayList();
    animals.add("Dog");
    animals.add("Elephant");
    animals.add("Ox");
    animals.add("Fox");
    return SUCCESS;

  }

  public List getFruits(){
    return fruits;
  }

  public List getAnimals(){
    return animals;
  }
}

Create a jsp using the tag <s:radio>.It renders  a radio button input field.

radioTag.jsp

<%taglib prefix="s" uri="/struts-tags" %>
<html>
    <head>
        <title>Radio Tag Example!</title> 
     <link href="<s:url value="/css/main.css"/>" rel="stylesheet"
          type="text/css"/>  
  </head>
    <body>
  <h1><span style="background-color: #FFFFcc">Radio Tag Example!</span></h>
  <s:form>
    <s:radio label="Fruits" name="fruitsname" list="fruits" />
    <s:radio label="Animals" name="animalsname" list="animals" />
  </s:form>
  </body>
</html>

Output of the radioTag.jsp:

 

                         

» View all related tutorials
Related Tags: html text ui sed textarea tag tar render tex to ext e area use ml m end s at htm

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

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.

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

Current Comments

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

I am facing one problem using Struts2:
I have 1 JSP in which a dynamically generated list is shown with checkboxes like below:

Sr No. Phase

[] 1 Analysis
[] 2 Operations
[] 3 harish
If I choose 2 of these & click on Edit button,how will I get the values of the checked row on the action class??
Please help me out..
Thanks in advance.
Anupkumar.

Posted by anupkumar on Tuesday, 10.7.08 @ 17:24pm | #80947

How do to render the tags of the radio button for td. Where to appear in several columns?

Posted by Solimar Alves dos Santos on Tuesday, 08.5.08 @ 19:52pm | #71144

Well I've exactly pasted this code and my radio button isn't displayed because of this error :

SEVERE: Servlet.service() for servlet jsp threw exception
tag 'radio', field 'list', name 'fruitsname': The requested list key 'fruits' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

Anyone know how to fix this error ?

Posted by Raiden on Wednesday, 04.30.08 @ 20:48pm | #58234

Hi,

Your website is very great and helpful.

I need small in my code using radio buttons.

So if you can give code changes for the following question, I can use it my bean.

In the above example,

1. if I want to set Mango in fruits list and Dog in animals list what code changes should be done at bean level.

2. To get the list of fruits and animals selected in JSP, what code changes needs to be done at bean level?

Thanks
Suresh

Posted by Suresh on Tuesday, 04.1.08 @ 01:17am | #54905

Dear Sahar,
You must use String type in Lists, not an Object:p (e.g. List<String> not List<Fruit>), Do not forget this for the next project!

Posted by Farzaneh on Sunday, 10.7.07 @ 16:25pm | #32334

Your list should be a Map. If it isn't, the key will be initialized to whatever the toString() method of the class returns: "action.fruits@f3hg"

Posted by Razvan on Wednesday, 09.26.07 @ 16:33pm | #29714

hi,
I have a class which has a field that must be filled by choosing one of the options of radio button on my web page. Assume I have selected apple option in above example, I expect the fruit field of class to be apple, but it contains value action.fruits@f3hg.
Do you have any ideas what the problem is.
Hope to receive an answer,
thanks

Posted by Sahar on Friday, 09.7.07 @ 18:06pm | #26315

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

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

Copyright © 2008. All rights reserved.