简体   繁体   中英

Howto set values of hashmap from Java class in JSP page for further usage in controller

Need some help solving the following issue.

I have web-application in Java, with Spring (mvc, security), Hibernate, and so on. Web pages sources are in JSP

I have a list of variables-indices, for which I need to set values and then automate it's processing. Say, client sees them in format:

A1.1 - Description - Dropdown list(0, 0.5, 1)
A1.2 - Description - Dropdown list(0, 0.5, 1)
...etc

Domain object is:

public class A1Model {
    private HashMap<Integer, Double> map;
    //initilising, getter and setter for map object
}

JSP page I have:

<form:form modelAttribute="m1ChapterModel" method="POST" action="${saveUrl}">
        <c:forEach items="${m1ChapterModel.map}" var="m1_parameter_i">           
                    A1.${m1_parameter_i.key}
                <spring2:message code="M1.1.label"/>
                <form:select path="${m1ChapterModel.map[m1_parameter_i.key]}">
                    <form:option value="0"/>
                    <form:option value="0.5"/>
                    <form:option value="1"/>
....

But thats not working, of course. The problem is:

<form:select path="${m1ChapterModel.map[m1_parameter_i.key]}">

Question is: how can i modify Java class and JSP to get it working?

instead of

<form:select path="${m1ChapterModel.map[m1_parameter_i.key]}">

use

<form:select path="map[${m1_parameter_i.key}]">

because the path variable wants the path, not the concrete value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM