AccountFormControllerpublic class AccountFormController extends org.springframework.web.servlet.mvc.SimpleFormController
Fields Summary |
---|
public static final String[] | LANGUAGES | private org.springframework.samples.jpetstore.domain.logic.PetStoreFacade | petStore |
Constructors Summary |
---|
public AccountFormController()
setSessionForm(true);
setValidateOnBinding(false);
setCommandName("accountForm");
setFormView("EditAccountForm");
|
Methods Summary |
---|
protected java.lang.Object | formBackingObject(javax.servlet.http.HttpServletRequest request)
UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession");
if (userSession != null) {
return new AccountForm(this.petStore.getAccount(userSession.getAccount().getUsername()));
}
else {
return new AccountForm();
}
| protected void | onBindAndValidate(javax.servlet.http.HttpServletRequest request, java.lang.Object command, org.springframework.validation.BindException errors)
AccountForm accountForm = (AccountForm) command;
Account account = accountForm.getAccount();
if (request.getParameter("account.listOption") == null) {
account.setListOption(false);
}
if (request.getParameter("account.bannerOption") == null) {
account.setBannerOption(false);
}
errors.setNestedPath("account");
getValidator().validate(account, errors);
errors.setNestedPath("");
if (accountForm.isNewAccount()) {
account.setStatus("OK");
rejectIfEmpty(errors, "account.username", "USER_ID_REQUIRED", "User ID is required.");
if (account.getPassword() == null || account.getPassword().length() < 1 ||
!account.getPassword().equals(accountForm.getRepeatedPassword())) {
errors.reject("PASSWORD_MISMATCH", "Passwords did not match or were not provided. Matching passwords are required.");
}
}
else if (account.getPassword() != null && account.getPassword().length() > 0) {
if (!account.getPassword().equals(accountForm.getRepeatedPassword())) {
errors.reject("PASSWORD_MISMATCH", "Passwords did not match. Matching passwords are required.");
}
}
| protected org.springframework.web.servlet.ModelAndView | onSubmit(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.Object command, org.springframework.validation.BindException errors)
AccountForm accountForm = (AccountForm) command;
if (accountForm.isNewAccount()) {
this.petStore.insertAccount(accountForm.getAccount());
}
else {
this.petStore.updateAccount(accountForm.getAccount());
}
UserSession userSession = new UserSession(this.petStore.getAccount(accountForm.getAccount().getUsername()));
PagedListHolder myList = new PagedListHolder(this.petStore.getProductListByCategory(accountForm.getAccount().getFavouriteCategoryId()));
myList.setPageSize(4);
userSession.setMyList(myList);
request.getSession().setAttribute("userSession", userSession);
return super.onSubmit(request, response, command, errors);
| protected java.util.Map | referenceData(javax.servlet.http.HttpServletRequest request)
Map model = new HashMap();
model.put("languages", LANGUAGES);
model.put("categories", this.petStore.getCategoryList());
return model;
| protected void | rejectIfEmpty(org.springframework.validation.Errors errors, java.lang.String field, java.lang.String errorCode, java.lang.String defaultMessage)
Object fieldValue = errors.getFieldValue(field);
if (fieldValue == null || fieldValue.toString().length() == 0) {
errors.rejectValue(field, errorCode, defaultMessage);
}
| public void | setPetStore(org.springframework.samples.jpetstore.domain.logic.PetStoreFacade petStore)
this.petStore = petStore;
|
|