나는 스프링 MVC의 내가 만든 양식에 액세스하려고 할 때 다음과 같은 오류를 받고 있어요에 대한 일반 대상 객체 어느 :java.lang.IllegalStateException : BindingResult도 빈 이름
java.lang.IllegalStateException를 : 어느 BindingResult도 'roomSelection'을 사용할 수 요청 속성 여기
같은 콩 이름에 대한 일반 대상 객체는 컨트롤러의 :
@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>
이것은 일반적인 초보자 문제인 것처럼 보이지만 내가 잘못하고있는 것을 파악할 수는 없습니다. 아이디어가 있으십니까?
감사합니다,
스티브
제출 또는 가져 오는 중에 오류가 발생합니까? 또한 나는 당신이 @ModelAttribute를 메서드와 함께 사용하고 ModelMap에 속성을 추가하는 것을 혼동하고있다. 하나에 붙어. – raddykrish
실제로보기가 호출 된 방식으로 문제가 판명되었습니다. 이보기를 호출하는 컨트롤러에서 "redirect :"를 추가하면 정상적으로 작동하는 것 같습니다. 하지만 여전히 혼란 스럽다. 정확히 리디렉션해야하는 이유는 무엇입니까? ModelMap 또는 @ModelAttribute를 고수해 주셔서 감사합니다. – SteveN