Bean property is not readable or has an invalid getter method

46,472

Solution 1

Add the form's getter method to the bean as indicated by the error message

public String getForm() {
   return form;
}

setForm should have a corresponding method

public void setForm(String form) {
   this.form = form;
}

Solution 2

add following

public String getForm(){
    return form;
}

public void setForm(String form){
    this.form = form;
    this.toList();
}
Share:
46,472
Padmelina
Author by

Padmelina

Updated on January 06, 2020

Comments

  • Padmelina
    Padmelina over 4 years

    So, I have a task to write a simple web-application for registry routes. Using Spring MVC. So I have class "Route", where I want to keep start point, finish point and list of intermediate points. But I don't understand, how to put values to list from jsp (e.g. using jstl). So I decide to parse a string.

    public class Route {
        private String start;
        private String finish;
        private String form;
        private List<String> list;
    
        public Route() {
        }
    
        public Route(String start, String finish, String route) {
            this.start = start;
            this.finish = finish;
            this.form = route;
            this.toList();
        }
    
        public Route(String start, String finish) {
            this.start = start;
            this.finish = finish;
            this.list = new ArrayList<>();
        }
    
        public void addTown(String town){
            list.add(town);
        }
    
        public String getStart() {
            return start;
        }
    
        public void setStart(String start) {
            this.start = start;
        }
    
        public String getFinish() {
            return finish;
        }
    
        public void setFinish(String finish) {
            this.finish = finish;
        }
    
        public List<String> getRoute() {
            return list;
        }
    
        public void setFormRoute(String route) {
            this.form = route; 
            this.toList();
        }    
    
        private void toList()
        {
            String[] temp = form.split(",");
            for(String temp1 : temp) {
                list.add(temp1);
            }
        }
    }
    

    and follow JSP:

    <h2><a href="find.htm">Найти существующий маршрут</a><br/><br/>
        Добавить маршрут</h2>
    <h3> 
        <spring:nestedPath path="route">
            <form modelAttribute="routeAttribute" method="POST" action="${add}">
                Пункт отправления:
                <spring:bind path="start">
                    <input type="text" name="${status.expression}" value="${status.value}">
                </spring:bind><br/><br/>                    
                Пункт прибытия:
                <spring:bind path="finish">
                    <input type="text" name="${status.expression}" value="${status.value}">
                </spring:bind><br/><br/>
                Промежуточные пункты (через запятую):
                <spring:bind path="form">
                    <input type="text" name="${status.expression}" value="${status.value}">
                </spring:bind><br/><br/>
    
                <input type="submit" value="Сохранить">
            </form>
        </spring:nestedPath>
    

    If it's nessesary I can post Controller code. And I have an error:

    Bean property 'form' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
    

    Can anyone, please, to explain what I do principaly wrong?