Doubleselect Tag (Form Tag) Example
In this section, we are going to describe the doubleselect
tag. The doubleselect tag is a UI tag that renders two HTML select elements
with second one changing displayed values depending on selected entry of first
one.
Add the following code snippet into the struts.xml file.
struts.xml
<action name="doubleselectTag">
<result>/pages/uiTags/doubleselectTag.jsp</result>
</action> |
Create a jsp using the tag
<s:doubleselect>
that renders two HTML select elements
with second one changing displayed values depending on selected entry of first
one. This tag contains various parameters:
The headerKey parameter sets the header key of
the second list. Must not be empty. In our case we have set it to"1"
The headerValue parameter sets the header value of
the second list. In our case we have set it to "--- Please Select ---"
The doubleName parameter sets the
name for complete component. In our case we have set it as : doubleName="dishes"
The doubleList sets the second iterable source to populate from. In our
case we have set it as :
doubleList="top == 'Color' ? {'Black','Green','White',
'Yellow','Red','Pink'} : { 'Apple','Banana','Grapes','Mango'}"
doubleselectTag.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Doubleselect Tag Example!</title>
</head>
<body>
<h1><span style="background-color: #FFFFcc">Doubleselect Tag Example!</span></h1>
<s:form>
<s:doubleselect label="Select Item"
headerValue="--- Please Select ---"
headerKey="1" list="{'Color','Fruits'}"
doubleName="dishes"
doubleList="top == 'Color' ? {'Black','Green','White',
'Yellow','Red','Pink'} : { 'Apple','Banana','Grapes','Mango'}" />
</s:form>
</body>
</html>
|
Output of the doubleselectTag.jsp:
|
Current Comments
9 comments so far (post your own) View All Comments Latest 10 Comments:I want to use Struts2 DoubleSelect Tag for populating List of countries and on selecting a country, its available cities should be populated. Can anybody give sugesstions and any practicle code for such scenario.
Thanks
Naresh Sahu
Posted by Naresh Sahu on Monday, 06.9.08 @ 10:50am | #62682
how to use this tag with a sample with databse and struts2 actions.
Posted by sunil on Wednesday, 06.4.08 @ 09:53am | #62040
Hi,
If you provide example like , list of country and their city.
will help us to understand better.
Posted by shambhu on Friday, 05.23.08 @ 09:52am | #60728
sir
If it possible morethan two elemnts in fisrt combo and change depending on second combo value
Posted by Rakesh on Saturday, 03.29.08 @ 13:04pm | #54650
Thanks Sathish, That was really helpful!!
Posted by Rushikesh on Wednesday, 02.27.08 @ 18:37pm | #50312
execute ur query.
then fetch the result into hash and keep it in list.
for ex.,
Execute Query :
SELECT COL1, COL2 FROM TBL;
create hash:
HashMap<String, String> resultMap =new HashMap();
store the query result into hash (resultMap)
then make select tag:
<HTML:SELECT list="resultMap" />
refer this link from our roseindia
http://www.roseindia.net/struts/struts2/struts2uitags/select-tag.shtml
if any problem, mention where ur facing problem.
Posted by sathish kumar on Monday, 02.25.08 @ 23:52pm | #50031
and also, try this url....
hope it helps you...
Posted by sathish on Saturday, 02.23.08 @ 23:51pm | #49692
get the data and store it into array....
and then initialize it...
reply in case of doubt...
Posted by sathish on Saturday, 02.23.08 @ 23:29pm | #49690
What to do if my lists come from database? Kindly help..
Posted by Rushikesh on Thursday, 02.7.08 @ 16:22pm | #47510