package com.vst.webapp.action;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import com.vst.webapp.action.BaseFormController;
import com.vst.model.AuthentificationElement;
import com.vst.service.AuthentificationElementManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
public class AuthentificationElementFormController extends BaseFormController {
private AuthentificationElementManager authentificationElementManager = null;
public void setAuthentificationElementManager(AuthentificationElementManager authentificationElementManager) {
this.authentificationElementManager = authentificationElementManager;
}
public AuthentificationElementFormController() {
setCommandName("authentificationElement");
setCommandClass(AuthentificationElement.class);
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
if (!isFormSubmission(request)) {
String authentificationId = request.getParameter("authentificationId");
AuthentificationElement authentificationElement = null;
if (!StringUtils.isEmpty(authentificationId)) {
authentificationElement = authentificationElementManager.getAuthentificationElement(authentificationId);
authentificationElementManager.evict(authentificationElement);
} else {
authentificationElement = new AuthentificationElement();
}
if (request.getParameter("edited") != null) {
request.setAttribute("addition", "?edited=1");
authentificationElement.setEdited(true);
}
return authentificationElement;
}
return super.formBackingObject(request);
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command,
BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
AuthentificationElement authentificationElement = (AuthentificationElement) command;
boolean isNew = (authentificationElement.getAuthentificationId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
authentificationElementManager.removeAuthentificationElement(authentificationElement.getAuthentificationId().toString());
saveMessage(request, getText("authentificationElement.deleted", locale));
} else {
authentificationElementManager.saveAuthentificationElement(authentificationElement);
String key = (isNew) ? "authentificationElement.added" : "authentificationElement.updated";
saveMessage(request, getText(key, locale));
if (authentificationElement.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + authentificationElement.getAuthentificationId() + "&fieldId=" + request.getParameter("fieldId"));
}
}
return new ModelAndView(getSuccessView());
}
}