Background
[wp_ad_camp_5]
So you’re using JSF and Spring. You thought your application is modern but then you hit a showstopper bug from either library that you could not retrieve the request parameters. Time to use some old-school Servlet/JSP API. This article demonstrates how to retrieve HttpServletRequest object in JSF.
Software Environment
- Windows 7 Professional SP1
- Eclipse – Kepler Release
- Java 1.7 (1.7.0_67 – Windows x86)
- JSF 2.1.26
- Spring 3.2.8
The Codes
[wp_ad_camp_4]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class AppointmentController extends AbstractController /* Usage: this.getHttpParameters().get('your_visual_control_id_in_html'); * * Note: Please this method inside your @ManagedBean class and do not * name your items with '_input' string in your facelets (*.xhtml). */ private Map getHttpParameters() { ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); Object requestObj = context.getRequest(); if(requestObj instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest)requestObj; .... } return params; // Map object } } |
[wp_ad_camp_3]