Last active
December 31, 2015 22:46
-
-
Save bjpeterdelacruz/01b490abd4671608096e to your computer and use it in GitHub Desktop.
Bill controller used to demonstrate how to access session object from validator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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