mfirry wrote:
hi,
i need to populate my combo with options taken from the FormBean and
compared with the Enum values.
i have it working but i doubt it's the best way to do it (and it mixes too
much struts tags with jstl ones, in my opinion)
anybody can help?
<[EMAIL PROTECTED] import="MyPackage.*" //this package contains the class with
the enum
used further down %>
<%! String val; %>
<html:form action="/full_profiloGiocoRespAutoesclusione">
<label>WANT TO DO THIS?</label>
<% String d2 = "session"; %>
<logic:notEmpty name="MyFormBean" property="duration">
<bean:define id="d1" name="MyFormBean" property="duration"/>
<% d2 = d1.toString();%>
</logic:notEmpty>
<fieldset>
<label for="question">Choose duration</label>
<html:select property="duration" name="MyFormBean">
<%
QuestionValues value;
String d = "session";
if (d2 != null) {
d = d2;
}
if ("day".equals(d)) {
value = QuestionValues.day;
}
else if ("week".equals(d)) {
value = QuestionValues.week;
} else {
value = QuestionValues.session;
}
for (QuestionValues v : QuestionValues.values()) {
if (v.compareTo(value) >= 0) {
val = (String) (v.getLabel());
%>
<html:option value='<%=val%>'><%=val%></html:option>
<% }
}
%>
</html:select>
</fieldset>
</html:form>
With all those scriptlets, mixing of taglib and RT expression values,
and the relevant Java code not included, it's a little difficult to see
exactly what you're attempting.
I'm assuming MyFormBean.duration's type is a custom enumeration with
with a getLabel() method, and that you want to use the label associated
with each enum value as both the label and value of the select options?
but you're using the enum value directly in the html:select?
It looks like it would be a lot cleaner and easier to handle the
conversion to and from enum values in your action, and let the form bean
and JSP deal with a simple list of Strings.
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]