I m having trouble to set value for entity bean. the problem is that when i populate form file will be upload but i need file path to store in data base. In my bean i have used setter of employee entity to set file url but And I think the code is enough to set file path for database but data is storing on database leaving employeePicture as null..
        @Named
        @RequestScoped
        public class EmployeeAddController {
            private Employees employees;
            private String fileNameForDataBase;
            private Part file;
            @Inject
            private EmployeeUpdateService updateService;
            @PostConstruct
            public void init() {
                employees = new Employees();
            }
            public Employees getEmployees() {
                return employees;
            }
            public void setEmployees(Employees employees) {
                this.employees = employees;
            }
            public String getFileNameForDataBase() {
                return fileNameForDataBase;
            }
            public void setFileNameForDataBase(String fileNameForDataBase) {
                this.fileNameForDataBase = fileNameForDataBase;
            }
            public Part getFile() {
                return file;
            }
            public void setFile(Part file) {
                this.file = file;
            }
            public void upload() throws IOException {
                ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance()
                        .getExternalContext().getContext();
                String realPath = ctx.getRealPath("/");
                int random =(int) (Math.random() * 10000 + 1);
                String fileString= realPath + File.separator + "resources/image/employee"+random+".jpg";
                employees.setEmployeePicture(fileString);
                try (InputStream input = file.getInputStream()) {
                    Files.copy(input, new File(fileString).toPath());
                }
            }
            public String addEmployee() {
                try {
                    this.updateService.add(employees);
                    return "index?faces-redirect=true";
                } catch (Exception e) {
                    return null;
                }
            }
        }
in My jsf page
 "<div class="form-group">
                                        <h:outputText value=" Employee Picture" class="col-sm-3 control-label"/>
                                        <div class="col-sm-9">
                                            <h:inputFile value="#{employeeAddController.file}">
                                                <f:ajax listener="#{employeeAddController.upload()}"/>
                                            </h:inputFile>
                                            <h:outputText value="#{employeeAddController.fileNameForDataBase}"/>
                                        </div>
                                        <div>
                                            <h:message for="fileUpload" class="text-primary"/>
                                        </div>
                                    </div>"***strong text***
