hi i would use
html:optionsCollection if you want to use the "selected=selected" feature
form.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%...@page import="java.util.ArrayList"%>
<%...@page import="java.util.Collection"%>
<%...@page import="java.util.Vector"%>
<%...@page import="org.apache.struts.util.LabelValueBean"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for TestNameForm form</title>
</head>
<body>
<%
Collection myList = new Vector();
for(int i=0;i<20;i++) {
myList.add(new LabelValueBean("label"+i, i+"value"));
}
pageContext.setAttribute("myList", myList);
%>
<html:form action="/testName">
name : <html:select property="name" *value="3value"*>
<html:optionsCollection name="myList" value="value"
label="label"/>
</html:select>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
*HTML-Output:*
<html>
<head>
<title>JSP for TestNameForm form</title>
</head>
<body>
<form name="testNameForm" method="post"
action="/Test/testName.do">
name : <select name="name"><option
value="0value">label0</option>
<option value="1value">label1</option>
<option value="2value">label2</option>
<option value="3value" selected="selected">label3</option>
<option value="4value">label4</option>
<option value="5value">label5</option>
<option value="6value">label6</option>
<option value="7value">label7</option>
<option value="8value">label8</option>
<option value="9value">label9</option>
<option value="10value">label10</option>
<option value="11value">label11</option>
<option value="12value">label12</option>
<option value="13value">label13</option>
<option value="14value">label14</option>
<option value="15value">label15</option>
<option value="16value">label16</option>
<option value="17value">label17</option>
<option value="18value">label18</option>
<option value="19value">label19</option></select>
<input type="submit" value="Submit"><input type="submit"
name="org.apache.struts.taglib.html.CANCEL" value="Cancel" onclick="bCancel=true;">
</form>
</body>
</html>
so its possible to set the default value by the 'value=""' attribute of the
html:select tag
<html:select property="name" *value="3value"*> ...of course the value must
match to any of your existing
values... otherwise the first option will be selected by default
I hope this was helpfull
Benny
Yves Dessertine wrote:
Hello,
I'm having a problem with <html:select> from the struts taglib. The
default option is only selected in the first example (but all 3 lists
are created well in jsp page). I googled a lot, but could't find
similar problem.
My JSP page contains 3 selects:
==============================================================
1) Default value selected:
<html:select name="afficheStockIAD" property="extractIntegrator">
<html:options name="afficheStockIAD"
property="listIntegratorNames" />
</html:select>
Generated output:
<select name="extractIntegrator"><option value="INT1">INT1</option>
<option value="INT2" selected="selected">INT2</option></select>
==============================================================
2) Default value not selected:
<html:select name="afficheStockIAD" property="extractYear">
<option value="<bean:write name="afficheStockIAD"
property="uberPreviousYear" />"><bean:write name="afficheStockIAD"
property="uberPreviousYear" /></option>
<option value="<bean:write name="afficheStockIAD"
property="previousYear" />"><bean:write name="afficheStockIAD"
property="previousYear" /></option>
<option value="<bean:write name="afficheStockIAD"
property="currentYear" />"><bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="<bean:write name="afficheStockIAD"
property="nextYear" />"><bean:write name="afficheStockIAD"
property="nextYear" /></option>
<option value="<bean:write name="afficheStockIAD"
property="uberNextYear" />"><bean:write name="afficheStockIAD"
property="uberNextYear" /></option>
</html:select>
Generated output:
<select name="extractYear"><option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option></select>
==============================================================
3) Default value not selected:
<html:select name="afficheStockIAD" property="extractMonth">
<option value="1">Janvier <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="2">Février <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="3">Mars <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="4">Avril <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="5">Mai <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="6">Juin <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="7">Juillet <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="8">Août <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="9">Septembre <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="10">Octobre <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="11">Novembre <bean:write name="afficheStockIAD"
property="currentYear" /></option>
<option value="12">Décembre <bean:write name="afficheStockIAD"
property="currentYear" /></option>
</html:select>
Generated output:
<select name="extractMonth"><option value="1">Janvier 2009</option>
<option value="2">Février 2009</option>
<option value="3">Mars 2009</option>
<option value="4">Avril 2009</option>
<option value="5">Mai 2009</option>
<option value="6">Juin 2009</option>
<option value="7">Juillet 2009</option>
<option value="8">Août 2009</option>
<option value="9">Septembre 2009</option>
<option value="10">Octobre 2009</option>
<option value="11">Novembre 2009</option>
<option value="12">Décembre 2009</option></select>
The afficheStockIAD.extractIntegrator, afficheStockIAD.extractYear and
afficheStockIAD.extractMonth are filled, and get transfered with the
formbean.
Formbean like this :
private String extractYear;
private String extractIntegrator;
private String extractMonth;
public String getExtractYear() {
return extractYear;
}
public void setExtractYear(String extractYear) {
this.extractYear = extractYear;
}
public String getExtractIntegrator() {
return extractIntegrator;
}
public void setExtractIntegrator(String extractIntegrator) {
this.extractIntegrator = extractIntegrator;
}
public String getExtractMonth() {
return extractMonth;
}
public void setExtractMonth(String extractMonth) {
this.extractMonth = extractMonth;
}
Help, if any ideas.
Regards,
Yves
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org