我有一个 Java 类“QueAndAns”,它有一个字段
private Map<String,String> questionAndAnswerMap;
在我的 JSP 页面上,我有
<form:form action="${submitURL}" method="POST" modelAttribute="queAndAns">
<c:forEach items="${queAndAns.questionAndAnswerMap}" var="questionAndAnswer" varStatus="status">
<form:input id="securityQuestions${status.index}" path="questionAndAnswerMap[${questionAndAnswer.key} ${questionAndAnswer.value}]"/>
<form:errors cssClass="errors" id="_securityQuestions_error_id" path="questionAndAnswerMap"/>
</c:forEach>
<input id="proceed" type="submit" value="${fn:escapeXml(find_button)}"/>
</form:form>
现在在我的控制器上,我想看看用户是否回答了所有问题,否则我想用bindingResult.rejectValue
. 我正在尝试这样的事情:
Map<String, String> questionAndAnswerMap = queAndAns.getQuestionAndAnswerMap();
Iterator<Map.Entry<String, String>> iterator = questionAndAnswerMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, String> map = iterator.next();
if (null == map.getValue() || StringUtils.isEmpty(map.getValue())) {
bindingResult.rejectValue("questionAndAnswerMap" , "err_qna_not_blank", "Please fill up the answer for security questions");
}
}
但它不工作。
有什么办法可以做到吗?