NotReadablePropertyException

NotReadablePropertyException

本文介绍了org.springframework.beans.NotReadablePropertyException:Bean类[java.lang.String]的无效属性'idValue':的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉列表,该下拉列表由我在控制器中生成,并将该值传递到我的jsp页面.我的"form:options"标签的"itemValue"属性中出现以下异常.为什么我需要itemValue的getter设置方法,因为但是我的"typeCode"具有值.但是为了避免混淆,我还为idValue添加了getter setter,但仍然遇到相同的错误.请帮助.

I have a dropdown, the value of which I am generating in my controller and passing that value to my jsp page. I am getting the following exception in the "itemValue" attribute of my "form:options" tag.Why do I need a getter setter for the itemValue because however I am having value for my "typeCode".But to avoid any confusion, I added getter setter for idValue also, but still getting the same error. Kindly help.

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:

OmxComboBean.java:

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

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

Bean类ClauseData.java:

Bean class 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)

推荐答案

您的控制器应该看起来像这样

Your controller should look like this

@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>

这篇关于org.springframework.beans.NotReadablePropertyException:Bean类[java.lang.String]的无效属性'idValue':的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:56