Skip to content

Instantly share code, notes, and snippets.

@bjpeterdelacruz
Last active December 31, 2015 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjpeterdelacruz/01b490abd4671608096e to your computer and use it in GitHub Desktop.
Save bjpeterdelacruz/01b490abd4671608096e to your computer and use it in GitHub Desktop.
Bill controller used to demonstrate how to access session object from validator
import org.springframework.web.servlet.mvc.SimpleFormController;
public class BillController extends SimpleFormController {
private BillService billService;
public BillController() {
setValidator(new BillValidator());
}
@Override
protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception {
Form form = (Form) command;
Bill bill = billService.getBill(form.getId());
BigDecimal paymentDue = bill.getPaymentDue(); // -1.19
// Add payment due as attribute to session object
request.getSession().setAttribute("paymentDue", paymentDue);
Map<String,Object> map = new HashMap<String,Object>();
// Populate JSP page with bill information, e.g. name, address, payment due, etc.
map.put("bill", bill);
return map;
}
@Override
protected void onBind(HttpServletRequest request, Object command) throws Exception {
((BillValidator) getValidator()).setRequest(request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment