0
votes

I am getting following error in my 'cmpmstaddedit.jsp':

org.springframework.beans.NotReadablePropertyException: Invalid property 'cmpcode' of bean class [java.util.ArrayList]: Bean property 'cmpcode' 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:725) org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:716) org.springframework.web.servlet.support.BindStatus.(BindStatus.java:149) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(AbstractDataBoundFormElementTag.java:188) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getName(AbstractDataBoundFormElementTag.java:154) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.autogenerateId(AbstractDataBoundFormElementTag.java:141) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.resolveId(AbstractDataBoundFormElementTag.java:132) org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.writeDefaultAttributes(AbstractDataBoundFormElementTag.java:116) org.springframework.web.servlet.tags.form.AbstractHtmlElementTag.writeDefaultAttributes(AbstractHtmlElementTag.java:422) org.springframework.web.servlet.tags.form.InputTag.writeTagContent(InputTag.java:142) org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84) org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspx_meth_form_005finput_005f0(cmpmstmgmt_jsp.java:330) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspx_meth_form_005fform_005f0(cmpmstmgmt_jsp.java:269) org.apache.jsp.WEB_002dINF.views.admin.cmpmstmgmt_jsp._jspService(cmpmstmgmt_jsp.java:123) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:618) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:725) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:85) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108) org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)

The file 'cmpmstaddedit.jsp' is as below:

<%-- 
    Document   : cmpmstaddedit
    Created on : Aug 3, 2014, 1:18:10 PM
--%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:url var="actionUrl" value="save" />

<form:form id="cmpmstForm" commandName="cmpmsts" method="post" action="${actionUrl}" class="pure-form pure-form-aligned">
    <fieldset>
        <legend></legend>
        <div class="pure-control-group">
            <label for="cmpcode">Code</label>
            <form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
        </div>
        <div class="pure-control-group">
            <label for="cmpdescr">Price</label>
            <form:input path="cmpdescr" placeholder="Company Description" maxlength="30" />
        </div>
        <div class="pure-control-group">
            <label for="cmpfybegin">Price</label>
            <form:input path="cmpfybegin" placeholder="F.Y. Begin Date" maxlength="15" />
        </div>
        <div class="pure-control-group">
            <label for="cmpfyend">Price</label>
            <form:input path="cmpfyend" placeholder="F.Y. End Date" maxlength="15" />
        </div>
    </fieldset>
</form:form>

My model file 'CmpMst.java' is as below:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nej.cmpmst.model;

/**
 *
 */
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="cmpmst", catalog = "nioerpj")
public class CmpMst {

    @Id
    private Byte cmpcode;
    private String cmpdescr;
    private Date cmpfybegin;
    private Date cmpfyend;

    public Byte getCmpcode() {
        return cmpcode;
    }
    public void setCmpcode(Byte cmpcode) {
        this.cmpcode = cmpcode;
    }

    public String getCmpdescr() {
        return cmpdescr;
    }
    public void setCmpdescr(String cmpdescr) {
        this.cmpdescr = cmpdescr;
    }

    public Date getCmpfybegin() {
        return cmpfybegin;
    }
    public void setCmpfybegin(Date cmpfybegin) {
        this.cmpfybegin = cmpfybegin;
    }

    public Date getCmpfyend() {
        return cmpfyend;
    }
    public void setCmpfyend(Date cmpfyend) {
        this.cmpfyend = cmpfyend;
    }

}

I have searched the internet and found many similar cases, however, even after applying the given solution doesn't resolved my issue. Can somebody help solving an issue? Do I need to upload any other file to arrive at a conclusion?

EDIT:

My Controller File CmpMstController.java is as below:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nej.controller;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.nej.cmpmst.model.CmpMst;
import com.nej.cmpmst.service.CmpMstService;

/**
 *
 */
@Controller
@RequestMapping(value={"/admin/cmpmstmgmt"})
public class CmpMstController {

    @Autowired
    private CmpMstService cmpmstService;

    @RequestMapping(value="/add", method=RequestMethod.GET)
    public ModelAndView addCmpMstPage() {
        ModelAndView modelAndView = new ModelAndView("CmpMst-add");
        modelAndView.addObject("cmpmstmgmt", new CmpMst());
        return modelAndView;
    }

    @RequestMapping(value="/add", method=RequestMethod.POST)
    public ModelAndView addingCmpMst(@ModelAttribute CmpMst cmpmst) {
        ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
        cmpmstService.addCmpMst(cmpmst);
        String message = "CmpMst was successfully added.";
        modelAndView.addObject("message", message);
        return modelAndView;
    }

    @RequestMapping(value={"/list","/"})
    public ModelAndView listOfCmpMsts() {
        ModelAndView modelAndView = new ModelAndView("/admin/cmpmstmgmt");
        List<CmpMst> cmpmsts = cmpmstService.getCmpMsts();
        modelAndView.addObject("cmpmsts", cmpmsts);
        return modelAndView;
    }

    @RequestMapping(value="/edit/{cmpcode}", method=RequestMethod.GET)
    public ModelAndView editCmpMstPage(@PathVariable Byte cmpcode) {
        ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
        CmpMst cmpmst = cmpmstService.getCmpMst(cmpcode);
        modelAndView.addObject("cmpmst",cmpmst);
        return modelAndView;
    }

    @RequestMapping(value="/edit/{cmpcode}", method=RequestMethod.POST)
    public ModelAndView editingCmpMst(@ModelAttribute CmpMst cmpmst, @PathVariable Byte cmpcode) {
        ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
        cmpmstService.updateCmpMst(cmpmst);
        String message = "CmpMst was successfully edited.";
        modelAndView.addObject("message", message);
        return modelAndView;
    }

    @RequestMapping(value="/delete/{cmpcode}", method=RequestMethod.GET)
    public ModelAndView deleteCmpMst(@PathVariable Byte cmpcode) {
        ModelAndView modelAndView = new ModelAndView("cmpmstmgmt");
        cmpmstService.deleteCmpMst(cmpcode);
        String message = "CmpMst was successfully deleted.";
        modelAndView.addObject("message", message);
        return modelAndView;
    }
}

My cmpmstmgmt.jsp is as below:

<%-- 
    Document   : cmpmstmgmt
    Created on : Jul 26, 2014, 6:00:28 PM
    Author     : Tushar
--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<tiles:insertDefinition name="defaultTemplate">
    <tiles:putAttribute name="body"> 

    <link rel="stylesheet" href='<c:url value="../../../resources/mytheme/styles/pure-0.4.2.css"/>'>
    <link rel="stylesheet" href='<c:url value="../../../resources/mytheme/styles/jquery-ui.css"/>'>
    <style type="text/css">
    th {
        text-align: left
    }
    </style>

    <div class="body">

    <div style="width: 95%; margin: 0 auto;">
    <div id="bookDialog" style="display: none;">
        <%@ include file="cmpmstaddedit.jsp"%>
    </div>
    <h1>List Of Company Master</h1>
    <button class="pure-button pure-button-primary" onclick="addCmpMst()">
        <i class="fa fa-plus"></i> Add Company Master
    </button>
    <br>
        <table class="pure-table pure-table-bordered pure-tablestriped">
            <thead>
                <tr>
                    <th width="4%">Sr.No.</th>
                    <th width="12%">Code</th>
                    <th width="12%">Company Description</th>
                    <th width="12%">F.Y. Begin Date</th>
                    <th width="12%">F.Y. End Date</th>
                    <th width="12%"></th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
                    <tr>
                        <td><c:out value="${loopCounter.count}" /></td>
                        <td><c:out value="${cmpmst.cmpcode}" /></td>
                        <td><c:out value="${cmpmst.cmpdescr}" /></td>
                        <td><c:out value="${cmpmst.cmpfybegin}" /></td>
                        <td><c:out value="${cmpmst.cmpfyend}" /></td>
                        <td>
                            <nobr>
                                <button onclick="editCmpMst(${cmpmst.cmpcode});"
                                    class="pure-button pure-buttonprimary">
                                    <i class="fa fa-pencil"></i> Edit
                                </button>
                                <a href="delete/${cmpmst.cmpcode}" class="pure-button pure-button-primary" onclick="return confirm('Are you sure you want to delete this CmpMst?');">
                                    <i class="fa fa-times"></i>Delete
                                </a>
                                </nobr>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
<!-- It is advised to put the <script> tags at the end of the document body so that they don't block rendering of the page -->
    <script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/jquery.js" />'></script>
    <script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/jquery-ui.js" />'></script>
    <script type="text/javascript" src='<c:url value="../../../resources/mytheme/script/js-for-listuser.js"/>'></script>
    </div>

    </tiles:putAttribute>
</tiles:insertDefinition>

I have uploaded controller file - CmpMstController.java and cmpmstmgmt.jsp file as above. Please suggest correction.

type Exception report

message An exception occurred processing JSP page /WEB-INF/views/admin/cmpmstaddedit.jsp at line 16

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/admin/cmpmstaddedit.jsp at line 16

13:         <legend></legend>
14:         <div class="pure-control-group">
15:             <label for="cmpcode">Code</label>
16:             <form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
17:         </div>
18:         <div class="pure-control-group">
19:             <label for="cmpdescr">Company Description</label>

EDIT: File - js-for-listcmpmst.js

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function addCmpMst() {
$('#cmpmstDialog').dialog("option", "title", 'Add Company');
$('#cmpmstDialog').dialog('open');
}
function editCmpMst(cmpcode) {
$.get("get/" + cmpcode, function(result) {
$("#cmpmstDialog").html(result);
$('#cmpmstDialog').dialog("option", "title", 'Edit Company');
$("#cmpmstDialog").dialog('open');
initializeDatePicker();
});
}
function initializeDatePicker() {
$(".datepicker").datepicker({
dateFormat : "dd/mm/yyyy",
changeMonth : true,
changeYear : true,
showButtonPanel : true
});
}
function resetDialog(form) {
form.find("input").val("");
}
$(document).ready(function() {
$('#cmpmstDialog').dialog({
autoOpen : false,
position : 'center',
modal : true,
resizable : false,
width : 440,
buttons : {
"Save" : function() {
    $('#cmpmstForm').submit();
    },
"Cancel" : function() {
    $(this).dialog('close');
    }
},
close : function() {
    resetDialog($('#cmpmstForm'));
    $(this).dialog('close');
    }
});
initializeDatePicker();
});

Edited Controller file:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nej.controller;

import com.nej.cmpmst.model.CmpMst;
import com.nej.cmpmst.service.CmpMstService;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Tushar
 */
@Controller
@RequestMapping(value={"/admin/cmpmstmgmt"})
public class CmpMstController {

    @Autowired
    private CmpMstService cmpmstService;


    @RequestMapping(value={"/list","/"})
    public String listOfCmpMsts(Map<String, Object> map ) {
        map.put("cmpmst", new CmpMst());

        map.put("cmpmstList", cmpmstService.getCmpMsts());

        return "/admin/cmpmstmgmt";
    }

    @RequestMapping("get/{cmpcode}")
    public String getCmpMst(@PathVariable Byte cmpcode, Map<String, Object> map) {
        CmpMst cmpmst = cmpmstService.getCmpMst(cmpcode);

        map.put("cmpmst", cmpmst);

        return "admin/cmpmstaddedit";
    }

    @RequestMapping(value="/save", method = RequestMethod.POST)
    public String saveCmpMst(@ModelAttribute("cmpmst") CmpMst cmpmst, BindingResult result) {
        cmpmstService.saveCmpMst(cmpmst);

        return "redirect:list";
    }

    @RequestMapping("/delete/{cmpcode}")
    public String deleteCmpMst(@PathVariable("cmpcode") Byte cmpcode) {
        cmpmstService.deleteCmpMst(cmpcode);

        return "redirect:/admin/cmpmstmgmt/";
    }


}

cmpmstaddedit.jsp

<%-- 
    Document   : cmpmstaddedit
    Created on : Aug 3, 2014, 1:18:10 PM
    Author     : Tushar
--%>

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:url var="actionUrl" value="save" />

<form:form id="cmpmstaddedit" commandName="cmpmst" method="post" action="${actionUrl}" class="pure-form pure-form-aligned">
    <fieldset>
        <legend></legend>
        <div class="pure-control-group">
            <label for="cmpcode">Code</label>
            <form:input path="cmpcode" placeholder="Company Code" maxlength="15" />
        </div>
        <div class="pure-control-group">
            <label for="cmpdescr">Company Description</label>
            <form:input path="cmpdescr" placeholder="Company Description" maxlength="30" />
        </div>
        <div class="pure-control-group">
            <label for="cmpfybegin">F.Y. Begin Date</label>
            <form:input path="cmpfybegin" placeholder="DD/MM/YYYY" class="datepicker" />
        </div>
        <div class="pure-control-group">
            <label for="cmpfyend">F.Y. End Date</label>
            <form:input path="cmpfyend" placeholder="DD/MM/YYYY" class="datepicker" />
        </div>
    </fieldset>
</form:form>
1
From the stacktrace, I would say the error is in a file name cmpmstmgmt.jsp does it exists ? Also it looks that you try to access property cmpcode from a List<CmpMst> instead of a CmpMst ...Serge Ballesta
@falcon Please post your controller code.Ankur Singhal
@ankur, I have uploaded cmpmstmgmt.jsp and controller CmpMstController.java files, please suggest.falcon
@Serge, cmpmstmgmt.jsp does exists and I have uploaded the same in my question above.falcon
@falcon Please give some hints regarding the flow, which method is called first, what view it redirects , then which jsp page is called.Ankur Singhal

1 Answers

1
votes

In the JSP file you have :

<c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
    <tr>
        <td><c:out value="${loopCounter.count}" /></td>
        <td><c:out value="${cmpmst.cmpcode}" /></td>

while ${cmpmst} is an array. You should write instead :

<c:forEach items="${cmpmst}" var="user" varStatus="loopCounter">
    <tr>
        <td><c:out value="${loopCounter.count}" /></td>
        <td><c:out value="${user.cmpcode}" /></td>

and same for following fields

I could not see how and where you forward to cmpmstaddedit.jsp in shown controller, but I assume that cmpmsts is also a list. You must ensure that you put a single object as request attribute before forwarding to that view.