title: Get user IP address with JSF API without the need for Servlet API
body: <p>I get some user data through a simple form. When dealing with the data in the corresponding backing bean's action method, I am currently getting the IP address of a user this way:</p>
  
  <pre><code>HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
  String ipAddress = request.getHeader( "X-FORWARDED-FOR" );
  if ( ipAddress == null ) {
      ipAddress = request.getRemoteAddr();
  }
  </code></pre>
  
  <p>Is there another way, a more "JSF" way, where I wouldn't need to hook on <code>HttpServletRequest</code>? I read many times that having to use <code>javax.servlet.*</code> in a <code>@ManagedBean</code> is not a good design, but I couldn't find anything else.</p>