作成した Spring MVC フォームにアクセスしようとすると、次のエラーが発生します。
java.lang.IllegalStateException: Bean 名 'roomSelection' の BindingResult もプレーン ターゲット オブジェクトも要求属性として使用できません
コントローラーは次のとおりです。
@Controller
@RequestMapping("/welcome")
public class RoomSelectionListController {
final private static String WELCOME_VIEW = "welcome";
final private static String SUCCESS_VIEW = "chatroom";
// Value will be injected.
private ChatRoomRegistryService chatRoomRegistryService = null;
private RoomSelectionValidator roomSelectionValidator = null;
private static Logger logger = Logger.getLogger(RoomSelectionListController.class);
public ChatRoomRegistryService getChatRoomRegistryService() {
return chatRoomRegistryService;
}
@Autowired
public void setChatRoomRegistryService(ChatRoomRegistryService chatRoomRegistryService) {
this.chatRoomRegistryService = chatRoomRegistryService;
}
@Autowired
public RoomSelectionListController(RoomSelectionValidator roomSelectionValidator) {
this.roomSelectionValidator = roomSelectionValidator;
}
@ModelAttribute("roomSelection")
protected RoomSelection getRoomSelection() {
logger.debug("Creating a RoomSelection instance");
return new RoomSelection();
}
@ModelAttribute("chatRoomList")
protected List<ChatRoom> populateChatRoomList(HttpServletRequest request) throws Exception{
logger.debug("Creating a chatRoomList");
User user = (User) request.getSession().getAttribute("userLoggedIn");
List<ChatRoom> chatRoomsForUser = chatRoomRegistryService.getChatRoomsForUser(user);
return chatRoomsForUser;
}
@RequestMapping(method = RequestMethod.POST)
protected String processSubmit(@ModelAttribute("roomSelection") RoomSelection roomSelection, BindingResult result, ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception {
roomSelectionValidator.validate(roomSelection, result);
if (result.hasErrors()) {
return WELCOME_VIEW;
} else {
model.addAttribute("chatroom", roomSelection.getChatRoom());
User user = (User) request.getSession().getAttribute("userLoggedIn");
model.addAttribute("userLoggedIn", user);
return SUCCESS_VIEW;
}
}
@RequestMapping(method = RequestMethod.GET)
protected String initForm(ModelMap model) throws Exception {
logger.debug("Inside RoomSelectionListController.initForm()");
RoomSelection roomSelection = new RoomSelection();
model.addAttribute("roomSelection", roomSelection);
return WELCOME_VIEW;
}
}
JSP のフォーム セクションは次のとおりです。
<form:form id="joinForm" modelAttribute="roomSelection" method="POST">
<table>
<legend><spring:message code="welcome.chatroom.list.lbl" /></legend>
<tr>
<td>
<form:select id="selectChatRoomList" path="chatRoomId" size="7" cssClass="chatRoomList">
<form:options items="${chatRoomList}" itemValue="chatRoomId"
itemLabel="chatRoomName" />
</form:select>
</td>
</tr>
<tr>
<td><form:errors path="chatRoomId" cssClass="advchatError" /></td>
</tr>
<tr>
<td>
<a id="submitJoinChatRoom" href="javascript:void(0)" class="green-button" onclick="$('#joinForm').submit();">
<span class="green-button-outer">
<span class="green-button-inner">
<div class="joinRoomButtonWidth"><spring:message code="welcome.joinchat.lbl" /></div>
</span>
</span>
</a>
</td>
</tr>
</table>
</form:form>
これは一般的な初心者の問題のようですが、何が間違っているのかわかりません。何か案は?
ありがとう、
スティーブ