【Java开源代码栏目提醒】:网学会员,鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“CollectionFormController.java”一文,供大家参考学习!
package com.myad.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import com.myad.model.Collection;
import com.myad.service.CollectionManager;
public class CollectionFormController extends SimpleFormController {
private Log log = LogFactory.getLog(CollectionFormController.class);
private CollectionManager collectionManager = null;
public void setCollectionManager(CollectionManager collectionManager) {
this.collectionManager = collectionManager;
}
public CollectionFormController() {
setCommandName("collection");
setCommandClass(Collection.class);
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
String collectionid = request.getParameter("collectionid");
Collection collection = null;
if (!StringUtils.isEmpty(collectionid)) {
collection = collectionManager.getCollection(collectionid);
} else {
collection = new Collection();
}
return collection;
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
Collection collection = (Collection) command;
boolean isNew = (collection.getCollectionid() == null);
if (request.getParameter("delete") != null) {
collectionManager.removeCollection(collection.getCollectionid()
.toString());
request.getSession().setAttribute(
"message",
getText("collection.deleted", collection
.getCollectiondescription()));
} else {
collectionManager.saveCollection(collection);
request.getSession().setAttribute(
"message",
getText("collection.deleted", collection
.getCollectiondescription()));
if (!isNew) {
return new ModelAndView("redirect:editCollection.html",
"collectionid", collection.getCollectionid());
}
}
return new ModelAndView(getSuccessView());
}
/**
* Convenience method for getting a i18n key's value. Calling
* getMessageSourceAccessor() is used because the RequestContext variable is
* not set in unit tests b/c there's no DispatchServlet Request.
*
* @param msgKey
* @return
*/
public String getText(String msgKey) {
return getMessageSourceAccessor().getMessage(msgKey);
}
/**
* Convenient method for getting a i18n key's value with a single string
* argument.
*
* @param msgKey
* @param arg
* @return
*/
public String getText(String msgKey, String arg) {
return getText(msgKey, new Object[] { arg });
}
/**
* Convenience method for getting a i18n key's value with arguments.
*
* @param msgKey
* @param args
* @return
*/
public String getText(String msgKey, Object[] args) {
return getMessageSourceAccessor().getMessage(msgKey, args);
}
}
上一篇:
CollectionFilterImpl.java
下一篇:
法律专业开题报告范文