org.springframework.beans.NotReadablePropertyException:bean类[java.lang.String]的属性'idValue'无效:

时间:2015-04-01 09:59:00

标签: jsp spring-mvc combobox

我有一个下拉列表,我在控制器中生成的值,并将该值传递给我的jsp页面。我在" itemValue"中收到以下异常我的"形式的属性:选项"标签。 为什么我需要itemValue的getter setter,因为我对我的" typeCode"有价值。 但为了避免任何混淆,我也为idValue添加了getter setter,但仍然得到了同样的错误。请帮助。

JSP:

<%
Map LCCLSTypeCode = (Map) request.getAttribute("LCCLSTypeCode"); 
System.out.println("LCCLSTypeCode:"+LCCLSTypeCode);
%>

<form:form action="/tradelc/ClsSave" method="POST" onsubmit="return CheckPassword()">
.
.
.
.
.
<form:select path="typeCode">
<form:options items="<%=LCCLSTypeCode%>" itemValue="idValue" itemLabel="displayValue"/>       
</form:select>

.
.
.
<a href="javascript:submitPageX();">Create</a>

<script>
function submitPageX() 
{
document.forms[0].submit();
            return false;
}

控制器:

@Controller
@SessionAttributes("clsData")
public class InformLoginAction{
@ModelAttribute("clsData")
    public ClauseData createBean() {
        return new ClauseData();
    }

@RequestMapping(value = "/informlogin", method = RequestMethod.GET)
    public ModelAndView execute( HttpServletRequest  request,
                                 HttpServletResponse response,
                                 @ModelAttribute("clsData") ClauseData clauseData,
                                 BindingResult bindingResult)
        throws Exception {
.
.
.
.
Map newMap = new HashMap();
while(enu!=null && enu.hasMoreElements())
        {
newMap.put(omxComboBean.assignId(item.trim()),omxComboBean.assignValue(text));
ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("menu1");
        modelAndView.addObject("command", new ClauseData());//Specifying the bean
        modelAndView.addObject("LCCLSTypeCode", newMap);//Specifying the value for the dropdown
        return modelAndView;
}
}

OmxComboBean.java:

public String assignId(String id)
    {
        idValue = id;
        return id;
    }

    public String assignValue(String value)
    {
        displayValue = value;
        return value;
    }

Bean类ClauseData.java:

public class ClauseData {
private String typeDesc;
private String idValue;
public String getTypeCode(){return typeCode;}
    public void setTypeCode(String typeCode){this.typeCode = typeCode;}
public String getIdValue(){return idValue;}
    public void setIdValue(String idValue){this.idValue = idValue;}
}

例外:

org.springframework.beans.NotReadablePropertyException: Invalid property 'idValue' of bean class [java.lang.String]: Bean property 'idValue' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:723)
    org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:714)
    org.springframework.web.servlet.tags.form.OptionWriter.renderFromMap(OptionWriter.java:166)
    org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:136)
    org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:155)
    org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)

1 个答案:

答案 0 :(得分:0)

您的控制器应如下所示

@RequestMapping(value = "/informlogin", method = RequestMethod.GET)
public ModelAndView execute(HttpServletRequest  request,HttpServletResponse response,@ModelAttribute("clsData") ClauseData clauseData,BindingResult bindingResult, ModelMap model) throws Exception {
    model.addAttribute("command", clauseData); // not modelAndView.addObject
    model.addAttribute("LCCLSTypeCode", map);
    ...
    return new ModelAndView("view name");
}

这里是jsp页面

<form:form action="/tradelc/ClsSave" method="POST" onsubmit="return CheckPassword()" path="command">
...
<form:select path="idValue">
    <form:options items="${LCCLSTypeCode}"/>   <!-- you should not use scriptlet and once map has been attached to ModelMap you don't need to retrive it mannually by scriptlet -->    
</form:select>
...
<a href="javascript:submitPageX();">Create</a>