Prefill form:textarea spring mvc

1.3k Views Asked by At

I've a <form:textarea> element. I would like to prefill it with data from the modelAttributes

Here's my code :

java :

ArrayList<Bloc> lblocs= new ArrayList<>();
lblocs = blocDao.getListBlocs();
modelMap.addAttributes("listeBlocs", lblocs);

Jsp :

    <form:form method="post" modelAttribute="listeBlocs">
        <c:forEach var="bloc" items="${listeBlocs}" varStatus="status">
            <form:textarea path="bloc_contenu" name="BContenu_textarea"
                 value="" />
        </c:forEach>
    </form:form>

bloc_contenu is supposed to be a String attribute to a Bloc object. When I load the page I get the following error :

Invalid property 'bloc_contenu' of bean class [java.util.ArrayList]: Bean property 'bloc_contenu' is not readable or has an invalid getter method

Any suggestions?

1

There are 1 best solutions below

0
On

change your textarea to this code

<form:form method="post" modelAttribute="listeBlocs">
    <c:forEach var="listeBlocs" items="${listeBlocs}" varStatus="status">
        <form:textarea path="bloc_contenu" name="BContenu_textarea">
            ${listeBlocs.columnName} 
        </form:textarea>
    </c:forEach>
</form:form>`

columnName is the name of the column in your database. you must have created it in model class with its getterts/setters!