Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:55:48+00:00 2026-06-11T05:55:48+00:00

The image property is not getting updated. I am using this.user.setImage(a) to set the

  • 0

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.

1)Here is my bean.The problem is in the handleFileUpload function.

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;
}


}

2)Here is my xhml page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<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">

<h:head></h:head>

    <h1> Main Content </h1>
    <h:form enctype="multipart/form-data">
    <h:panelGrid columns="2">
                    <h:outputText value="Profile Image"/>
                    <p:fileUpload fileUploadListener="#{userUpdateBean.handleFileUpload}"/>
                    <h:outputText value="Username: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.userName}" />
                    <h:outputText value="Firstname: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.firstName}" />
                    <h:outputText value="Lastname: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.lastName}" />
                    <h:outputText value="Password: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.password}" />
                    <h:outputText value="Date of Birth: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.birthDate}" >
                                <f:convertDateTime pattern="dd/MM/yyyy"></f:convertDateTime>
                                </p:inputText>
                    <h:outputText value="Gender: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.gender}" />
                    <h:outputText value="Relationship: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.relationship}" />  
                    <h:outputText value="EmailID: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.email}" /> 
                    <h:outputText value="Contact No.: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.contactNo}" />
                    <h:outputText value="Street: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.street}" />
                    <h:outputText value="City: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.city}" />  
                    <h:outputText value="Pincode: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.pincode}" />   
                    <h:outputText value="State: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.state}" />
                    <h:outputText value="Country: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.country}" />       
                    <h:outputText value="Secondary School: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.secondarySchool}" />
                    <h:outputText value="High School: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.highSchool}" />
                    <h:outputText value="College: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.college}" />   
                    <h:outputText value="University: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.university}" />
                    <h:outputText value="Degree: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.degree}" />
                    <h:outputText value="Quote: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.quote}" />
                    <h:outputText value="About Me: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.aboutMe}" />   
                    <h:outputText value="Interest: " />
                    <p:inputText styleClass="outputLabel"
                                value="#{userUpdateBean.user.interest}" />                                                                                                                                                                                                                                                      
                    <h:outputText />
                    <h:outputText />
                    <h:commandButton value="Update" action="#{userUpdateBean.update}"/>
                    </h:panelGrid>
                    </h:form>


</h:body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:55:49+00:00Added an answer on June 11, 2026 at 5:55 am

    Your problem is caused by a combination of those 2 causes:

    1. The bean is request scoped.
    2. The <p:fileUpload> is running in “advanced mode” (with browse, upload and cancel buttons).

    A request scoped bean has a lifetime of exactly one HTTP request. Uploading a file using <p:fileUpload> button accounts as one HTTP request. Submitting the form accounts as another HTTP request, with its own brand new instance of the bean. You should have noticed it by user.getImage() being null/empty during em.persist() while doing a simple debug.

    In order to get it to work, you need to put the bean in the view scope. This way the bean will live as long as you’re interacting with the same view.

    @ManagedBean
    @ViewScoped
    public class UserUpdateBean {}
    

    (or with <managed-bean-scope>view when using the old fashioned XML config approach)

    An alternative is to set <p:fileUpload> to “simple mode” so that it comes with only a browse button and get uploaded only when you actually submit the form. This way the uploaded file will be set during the same HTTP request as when the form is submitted.

    <p:fileUpload ... mode="simple" />
    

    See also:

    • How to choose the right bean scope?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not getting my image working. Can anyone tell me what I am
I have given a table background image using css background-image property. The cells are
I have an icon that is inserted into a page using the background-image property.
I'm using MVVM and am trying to databind the Source property of Image to
I am saving a image into database with byte[] property like this: ProfileModel: private
I do not understand why i am getting this error. Here is the related
I'm getting the error Object reference not set to an instance of an object.
I'm not getting EPiImage to show me the image when I use it in
I'm not sure how to achieve it but the image below shows the size
I'd like to use the image property tag constants defined in GDI+ from .NET.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.