Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.seguriboxltv.backing; import com.seguriboxltv.core.domain.User; import com.seguriboxltv.core.service.UserService; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * * @author IngGerman */ @Component @ManagedBean @RequestScoped public class AdminUserBean { @Autowired private UserService userService; private User user = new User(); public UserService getUserService() { return userService; } public void setUserService(UserService userService) { this.userService = userService; } public void save() { try { userService.Create(user, GetIp(), "gerhl92"); } catch (Exception e) { e.printStackTrace(); } } private String GetIp() { HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest(); String ipAddress = request.getHeader("X-FORWARDED-FOR"); if (ipAddress == null) { ipAddress = request.getRemoteAddr(); } return ipAddress; } }