apcausey
Sep 12th, 2007, 12:11 PM
I am using the portlet MVC (almost identical to the Web MVC). For some reason, when I implement the referenceData method, the onSubmit methods are not called when the form is submitted.
When the page first loads, formBackingObject is called twice (I don't know why twice), followed by referenceData. When the form is submitted, the same thing happens (formBackingObject followed by referenceData) - but neither onSubmit is called. I'm at a loss, because if I comment out the referenceData method and submit the form, the onSubmit methods are called! But I need to use the referenceData method.
public class MovieEditController extends SimpleFormController {
private MovieService movieService;
/*
* (non-Javadoc)
*
* @see org.springframework.web.portlet.mvc.AbstractFormCo ntroller#formBackingObject(javax.portlet.PortletRe quest)
*/
@Override
protected Object formBackingObject(PortletRequest request) throws Exception {
// create and return the MoviePreferences
MoviePreferences moviePreferences = new MoviePreferences(request
.getPreferences());
return moviePreferences;
}
@Override
public void onSubmitAction(ActionRequest request, ActionResponse response,
Object command, BindException error) throws Exception {
MoviePreferences moviePreferences = (MoviePreferences) command;
moviePreferences.savePreferences();
}
@Override
protected ModelAndView onSubmitRender(RenderRequest request,
RenderResponse response, Object command, BindException errors)
throws Exception {
ModelAndView mav = new ModelAndView();
mav.setView(this.getSuccessView());
Map<String, Object> model = new HashMap<String, Object>();
model.put("theaterSet", this.movieService.getAllTheaters(Calendar
.getInstance()));
mav.addAllObjects(model);
return mav;
}
@Override
protected Map referenceData(PortletRequest request) throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
model.put("theaterSet", this.movieService.getAllTheaters(Calendar
.getInstance()));
return model;
}
/**
* @return the movieService
*/
public MovieService getMovieService() {
return this.movieService;
}
/**
* @param movieService
* the movieService to set
*/
public void setMovieService(MovieService movieService) {
this.movieService = movieService;
}
}
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<portlet:actionURL var="actionURL" portletMode="edit" />
<form:form commandName="moviePreferences" action="${actionURL}">
<div style="padding-bottom: 10px">
Select theaters to view movie showtimes.
</div>
<c:forEach var="theater" items="${theaterSet}" varStatus="vs">
<div style="<c:if test='${vs.last}'>padding-bottom: 10px</c:if>">
<form:checkbox path="theaters" value="${theater.id}" />
<c:out value="${theater.name}" />
</div>
</c:forEach>
<input type="submit" value="Save" />
</form:form>
When the page first loads, formBackingObject is called twice (I don't know why twice), followed by referenceData. When the form is submitted, the same thing happens (formBackingObject followed by referenceData) - but neither onSubmit is called. I'm at a loss, because if I comment out the referenceData method and submit the form, the onSubmit methods are called! But I need to use the referenceData method.
public class MovieEditController extends SimpleFormController {
private MovieService movieService;
/*
* (non-Javadoc)
*
* @see org.springframework.web.portlet.mvc.AbstractFormCo ntroller#formBackingObject(javax.portlet.PortletRe quest)
*/
@Override
protected Object formBackingObject(PortletRequest request) throws Exception {
// create and return the MoviePreferences
MoviePreferences moviePreferences = new MoviePreferences(request
.getPreferences());
return moviePreferences;
}
@Override
public void onSubmitAction(ActionRequest request, ActionResponse response,
Object command, BindException error) throws Exception {
MoviePreferences moviePreferences = (MoviePreferences) command;
moviePreferences.savePreferences();
}
@Override
protected ModelAndView onSubmitRender(RenderRequest request,
RenderResponse response, Object command, BindException errors)
throws Exception {
ModelAndView mav = new ModelAndView();
mav.setView(this.getSuccessView());
Map<String, Object> model = new HashMap<String, Object>();
model.put("theaterSet", this.movieService.getAllTheaters(Calendar
.getInstance()));
mav.addAllObjects(model);
return mav;
}
@Override
protected Map referenceData(PortletRequest request) throws Exception {
Map<String, Object> model = new HashMap<String, Object>();
model.put("theaterSet", this.movieService.getAllTheaters(Calendar
.getInstance()));
return model;
}
/**
* @return the movieService
*/
public MovieService getMovieService() {
return this.movieService;
}
/**
* @param movieService
* the movieService to set
*/
public void setMovieService(MovieService movieService) {
this.movieService = movieService;
}
}
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<portlet:actionURL var="actionURL" portletMode="edit" />
<form:form commandName="moviePreferences" action="${actionURL}">
<div style="padding-bottom: 10px">
Select theaters to view movie showtimes.
</div>
<c:forEach var="theater" items="${theaterSet}" varStatus="vs">
<div style="<c:if test='${vs.last}'>padding-bottom: 10px</c:if>">
<form:checkbox path="theaters" value="${theater.id}" />
<c:out value="${theater.name}" />
</div>
</c:forEach>
<input type="submit" value="Save" />
</form:form>