Note that there are some explanatory texts on larger screens.

plurals
  1. POImage not getting updated
    text
    copied!<p>The image property is not getting updated. I am using this.user.setImage(a) to set the value but its not working.My managed bean is request scoped.</p> <p>1)Here is my bean.The problem is in the handleFileUpload function.</p> <pre><code>package com.bean; import javax.faces.context.FacesContext; import javax.faces.event.PhaseId; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import javax.servlet.http.HttpSession; import org.primefaces.event.FileUploadEvent; import org.primefaces.model.UploadedFile; import com.entity.User; public class UserUpdateBean { User user; private EntityManager em; private UploadedFile uploadedFile; public UserUpdateBean(){ EntityManagerFactory emf=Persistence.createEntityManagerFactory("FreeBird"); em=emf.createEntityManager(); FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(true); User s=(User) session.getAttribute("userdet"); user = em.find(User.class,s.getEmail()); } public void handleFileUpload(FileUploadEvent e) { System.out.println("file handler called"); uploadedFile = e.getFile(); String fileName=uploadedFile.getFileName(); fileName=fileName.substring(fileName.lastIndexOf("\\")+1); System.out.println(fileName); byte[] a = uploadedFile.getContents(); PhaseId currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId(); System.out.println("current phase id"+currentPhaseId); user.setImage(a); } public String update(){ em.getTransaction().begin(); em.persist(user); em.getTransaction().commit(); System.out.println("updated successful"); FacesContext context = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) context.getExternalContext().getSession(true); session.setAttribute("userdet", user); return "success"; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } } </code></pre> <p>2)Here is my xhml page.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"&gt; &lt;h:head&gt;&lt;/h:head&gt; &lt;h1&gt; Main Content &lt;/h1&gt; &lt;h:form enctype="multipart/form-data"&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:outputText value="Profile Image"/&gt; &lt;p:fileUpload fileUploadListener="#{userUpdateBean.handleFileUpload}"/&gt; &lt;h:outputText value="Username: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.userName}" /&gt; &lt;h:outputText value="Firstname: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.firstName}" /&gt; &lt;h:outputText value="Lastname: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.lastName}" /&gt; &lt;h:outputText value="Password: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.password}" /&gt; &lt;h:outputText value="Date of Birth: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.birthDate}" &gt; &lt;f:convertDateTime pattern="dd/MM/yyyy"&gt;&lt;/f:convertDateTime&gt; &lt;/p:inputText&gt; &lt;h:outputText value="Gender: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.gender}" /&gt; &lt;h:outputText value="Relationship: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.relationship}" /&gt; &lt;h:outputText value="EmailID: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.email}" /&gt; &lt;h:outputText value="Contact No.: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.contactNo}" /&gt; &lt;h:outputText value="Street: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.street}" /&gt; &lt;h:outputText value="City: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.city}" /&gt; &lt;h:outputText value="Pincode: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.pincode}" /&gt; &lt;h:outputText value="State: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.state}" /&gt; &lt;h:outputText value="Country: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.country}" /&gt; &lt;h:outputText value="Secondary School: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.secondarySchool}" /&gt; &lt;h:outputText value="High School: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.highSchool}" /&gt; &lt;h:outputText value="College: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.college}" /&gt; &lt;h:outputText value="University: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.university}" /&gt; &lt;h:outputText value="Degree: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.degree}" /&gt; &lt;h:outputText value="Quote: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.quote}" /&gt; &lt;h:outputText value="About Me: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.aboutMe}" /&gt; &lt;h:outputText value="Interest: " /&gt; &lt;p:inputText styleClass="outputLabel" value="#{userUpdateBean.user.interest}" /&gt; &lt;h:outputText /&gt; &lt;h:outputText /&gt; &lt;h:commandButton value="Update" action="#{userUpdateBean.update}"/&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; &lt;/h:body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload