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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials:
 

Software Solutions and Services
 

 
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments
 
Checkboxlist Tag (Form Tag) Example 
 

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

 

Checkboxlist Tag (Form Tag) Example

                         

In this section, we are going to describe the checkboxlist tag. The checkboxlist tag is a UI tag that creates a series of checkboxes from a list. Setup is like <s:select /> or <s:radio />, but creates checkbox tags.

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

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

Create two lists in the action class and populate them with various items as shown in the  "checkboxlistTag" class.

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 tags

<s:checkboxlist name="Fruits-name" list="fruits" /> it prints a checboxlist with name Fruits and Creates a series of checkboxes from fruits list of the action class "checkboxlistTag".  <s:checkboxlist name="Animals-name" list="animals" /> it prints a checboxlist with name Animals and Creates a series of checkboxes from animals list of the action class "checkboxlistTag".

checkboxlistTag.jsp

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

<html>
  <head> 
    <title>Checkboxlist  (Form TagTag Example!</title>
  </head>
  <body>
    <h1><span style="background-color: #FFFFcc">Checkboxlist 
                   Tag Example!</span></h1>

      <b>Fruits</b><br>
      <s:checkboxlist name="Fruits-name" list="fruits" /><br>
      
<b>Animals</b><br>
      <s:checkboxlist name="Animals-name" list="animals" />
<br>
  </body>
</html>

Output of the checkboxlistTag.jsp:

                         

» View all related tutorials
Related Tags: c orm select form parameters button io tags sed get double tag parameter ddl id ai element move elements buttons

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 have a question: What do we need to do to get these checkboxes vertically aligned instead of horizontally..
[]Apple
[]Mango
[]Orange

Posted by Abin on Monday, 09.8.08 @ 15:00pm | #77995

The Map can be iterated as follows

<s:set name="myMap" value="#{'Persian':'cat','St Bernard':'dog','Goliath Goliath':'bug','Bottlenose':'dolphin','Python':'snake'}" />


<s:iterator status="stat" value="myMap" >
<s:property value="key"/>
<s:property value="value"/>
<br/>
</s:iterator>

Posted by saket on Wednesday, 12.19.07 @ 22:34pm | #42997

Hi,

I'm trying to iterate a map like the following but it's not producing any output. Can anyone tell me why?

<s:set name="myMap" value="{'Persian':'cat','St Bernard':'dog','Goliath Goliath':'bug','Bottlenose':'dolphin','Python':'snake'}" />

<s:iterator status="stat" value="myMap" >
${key}
${value}
</s:iterator>

Posted by Billy on Tuesday, 12.4.07 @ 06:06am | #41222

Hi,

I'm trying to iterate a map like the following but it's not producing any output. Can anyone tell me why?

<s:set name="myMap" value="{'Persian':'cat','St Bernard':'dog','Goliath Goliath':'bug','Bottlenose':'dolphin','Python':'snake'}" />

<s:iterator status="stat" value="myMap" >
${key}
${value}
</s:iterator>

Posted by Billy on Tuesday, 12.4.07 @ 06:04am | #41221

Hi there

When i try running above example i always get following error:

"field 'list', name 'daysname': The requested list key 'fruits' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]"

What am i doing wrong?
Thanks a lot for your help!


Greetings from Rwitzerland,
Raoul

Posted by Raoul on Thursday, 11.1.07 @ 20:17pm | #35335

Hi,friends
i want to implement a selective list of elements(for example, email list) with checkboxlist and perform an operation(like deletion) on selected items.(like, delete email in yahoomail).Help Me PLZZZZ ;-(

Posted by Farshid on Thursday, 08.16.07 @ 10:54am | #23487

How do we use default selection?

Posted by Volkan Ozyilmaz on Tuesday, 08.7.07 @ 19:41pm | #22879

Training Courses
Tell A Friend
Your Friend Name
Website Designing Services
 
Web Designing Packages From $150!
 
Website Designing Company Web Hosting
 
Website Designing Quotation
 
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.