У меня есть следующий HTML-файл. Он использует Thymeleaf:Динамическое формирование имени HTML-формы
<form action="#" th:action="@{/heart2heart/token/__${tokenId}__/}" method="post">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover table-condensed">
<tr>
<th style="display:none;"></th>
<th th:text="#{service.desc}">Service</th>
<th th:text="#{feedback.description}">Feedback</th>
<th th:text="#{visit.date}">Date of Visit</th>
<th th:text="#{repr.name}">FU Repr</th>
<th th:text="#{resolution.response}">Response</th>
<th th:text="#{resolution.satisfactionLevel}">Satisfaction</th>
<th th:text="#{resolution.comment}">Comment</th>
</tr>
<tr th:each="feedback : ${feedbacks}">
<td style="display:none;"><input type="hidden" name="feedbackIds" th:value="${feedback.id}" /></td>
<td th:text="${feedback.service.description}">Steel</td>
<td th:text="${feedback.description}">Problem</td>
<td th:text="${feedback.visits[0].date}">12/08/2015</td>
<td th:text="${feedback.visits[0].repr.fullName}">XYZ</td>
<td th:text="${feedback.receipt.resolutions[0].response}">response</td>
<td>
<div class="radio">
<label><input type="radio" name="satisfaction" th:text="#{global.yes}" value="SATISFIED">Yes</input></label>
</div>
<div class="radio">
<label><input type="radio" name="satisfaction" th:text="#{global.no}" value="NOT SATISFIED">No</input></label>
</div>
</td>
<td><textarea class="form-control" rows="2" id="comment" name="comment"></textarea></td>
</tr>
</table>
<div class="form-group">
<button type="submit" name="addRow" th:text="#{button.submit}"
class="btn btn-primary btn-md">Submit</button>
</div>
</div>
</form>
Моя форма:
public class ReceiptForm {
private HashMap<Integer, String> comments;
private int[] feedbackIds;
private HashMap<Integer, String> satisfactions;
public HashMap<Integer, String> getComments() {
return comments;
}
public int[] getFeedbackIds() {
return feedbackIds;
}
public HashMap<Integer, String> getSatisfactions() {
return satisfactions;
}
public void setComments(HashMap<Integer, String> comments) {
this.comments = comments;
}
public void setFeedbackIds(int[] feedbackIds) {
this.feedbackIds = feedbackIds;
}
public void setSatisfactions(HashMap<Integer, String> satisfactions) {
this.satisfactions = satisfactions;
}
}
В текущем коде, входы одинаковы для всех итераций. Требование состоит в том, что входы формы satisfaction
и comment
будут раздельными для каждого feedback
. Длина feedbacks
меняется каждый раз, поэтому я не могу дать им статические имена. Как мне это сделать? Также, как я должен записывать эти данные в форме Java?
Почему длина такого фактора здесь, если я могу спросить? – Vaelyr
@Vaelyr Длина 'отзывов' меняется каждый раз, поэтому я не могу дать им статические имена. – khateeb