2014-03-07 77 views
0

我在JSP中有下面的代码。问题是,当我运行此代码,我得到以下例外:OptionTag类型中的方法setValue(String)不适用于参数(Object)

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> 
+0

的异常,因为我加入代码更改像”> – Narayan

回答

1

documentation<bean:define>标签结果判定为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> 
+0

嗨安东尼,我试过这两个解决方案。但我没有得到任何例外,而是转发到默认错误页面 – Narayan

+0

@ user3392877并且?听起来应该有第二部分。他们中的任何一个工作?如果不是,发生了什么,为什么不是你所期望的? –

+0

我没有看到任何异常,因为它看起来两个实现所需的值都没有到来。所以它转发到默认错误页面 – Narayan

相关问题