OptionTag类型中的方法setValue(String)不适用于参数(Object)

时间:2014-03-07 13:45:11

标签: java jsp struts

我的JSP中有以下代码。问题是当我运行此代码时,我得到以下异常:

The method setValue(String) in the type OptionTag is not applicable for the arguments (Object).  

有没有人有想法?

<html:select property="selectedServices" name="specificStoreForm" multiple="true" styleClass="services">
  <logic:iterate id="service" name="services" property="selectedServices">
  <bean:define id="textVal" name="service" property="value" toScope="request"/>
  <html:option value="<%=textVal%>">
    <bean:write name="service" property="label"/>
  </html:option>
  </logic:iterate>
</html:select>

1 个答案:

答案 0 :(得分:1)

如果您未指定<bean:define>属性,则从documentation判断Object标记的结果属于value类型。仅当传递的值为<html:option>类型时,String标记才有效。

使用EL(表达式语言)来获取值:

<html:option value="${textVal}">
    ...
</html>

您也可以使用<html:optionsCollection>标记,而不必显式迭代:

<html:select property="selectedServices" name="specificStoreForm" multiple="true" styleClass="services">
    <html:optionsCollection name="services" property="selectedServices" value="value" label="label"/>
</html:select>
相关问题