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

  • SEARCH
  • Home
  • 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 7713105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:47:14+00:00 2026-06-01T01:47:14+00:00

I’m trying to replicate the example of https://www.primefaces.org/showcase/ui/multimedia/photoCam.xhtml with a simple variation. In the

  • 0

I’m trying to replicate the example of https://www.primefaces.org/showcase/ui/multimedia/photoCam.xhtml with a simple variation.

In the example, every taken picture is saved and showed.

But I just need to show the latest one, so I’ve removed the list references and edited the code a little bit.

So I’m using just the graphicsImage instead of the imageSwitch, and, in the onCapture method I just overwrite the previous image.

But here’s the problem.

The new image is correctly taken, I can see it by browsing to its folder, but it won’t be updated in the page.
It seems that it still shows the previous cached one, because it works if it’s the first one (no file before this take).

Any suggestion?

EDIT:
Here some code.

PrimeFaces JSF

<h:form>  

<h:panelGrid columns="3">  
    <p:photoCam widgetVar="pc" listener="#{photoCamBean.oncapture}" update="photos"/>  

    <p:commandButton type="button" value="Capture" onclick="pc.capture()"/>  

    <p:imageSwitch effect="zoom" id="photos">  
        <ui:repeat value="#{photoCamBean.photos}" var="photo">  
            <p:graphicImage value="/photocam/#{photo}.png" />  
        </ui:repeat>  
    </p:imageSwitch>  
</h:panelGrid>  

MY JSF

<p:photoCam widgetVar="pc" listener="#{registerBean2.onCapture}" update="photo"/>
    <p:commandButton type="button" value="Capture" onclick="pc.capture()" update="photoPanel"/>
    <p:panel id="photoPanel">
        <p:graphicImage value="./uploaded/temp/#{registerBean2.utente.username}.png" id="photo">
            <p:effect type="pulsate" event="load" delay="500">
                <f:param name="mode" value="'show'" />
            </p:effect>
        </p:graphicImage>
    </p:panel> 

PRIMEFACES BEAN

public void oncapture(CaptureEvent captureEvent) {  
    String photo = getRandomImageName();  
    this.photos.add(0,photo);  
    byte[] data = captureEvent.getData();  

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
    String newFileName = servletContext.getRealPath("") + File.separator + "photocam" + File.separator + photo + ".png";  

    FileImageOutputStream imageOutput;  
    try {  
        imageOutput = new FileImageOutputStream(new File(newFileName));  
        imageOutput.write(data, 0, data.length);  
        imageOutput.close();  
    }  
    catch(Exception e) {  
        throw new FacesException("Error in writing captured image.");  
    }  
}  

MY BEAN

public void onCapture(CaptureEvent captureEvent) {
    makeAvatar(captureEvent.getData());
}

private void makeAvatar(byte[] imageData) {
    FileImageOutputStream imageOutput;
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    File imageFile = new File(extContext.getRealPath("NEW//uploaded//temp") + "//" + utente.getUsername() + ".png");
    try {
        if (imageFile.exists()) {
            imageFile.delete();
        }
        imageFile.createNewFile();
        imageOutput = new FileImageOutputStream(imageFile);
        imageOutput.write(imageData, 0, imageData.length);
        imageOutput.close();
        FacesMessage msg = new FacesMessage("Immagine caricata correttamente.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    } catch (Exception e) {
        FacesMessage msg = new FacesMessage("Errore nel caricamento dell'immagine!");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }
}

The image is captured and updated in my temp folder, but it won’t change in the page.
Even a refresh won’t help me.
It changes only after a server restart !

EDIT :
Here’s my glassfish-web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
    <class-loader delegate="true"/>
    <jsp-config>
         <property name="keepgenerated" value="true">
             <description>Keep a copy of the generated servlet class' java code.</description>
         </property>
         <property name="alternatedocroot_1" value="from=/uploads/* dir=/home/stefano/Documenti/UniLife" />
    </jsp-config>
 </glassfish-web-app>

Using Daniel’s solution, I should have been able to browse to localhost:8080/Unilife5-war/uploads/avatar/cp99.png to show /home/stefano/Documenti/UniLife/avatar/cp99.png , or I’m getting wrong?

  • 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-01T01:47:15+00:00Added an answer on June 1, 2026 at 1:47 am

    Not familiar with glassfish to well… but for a start I’d use the simplest example given by BalusC

    PrimeFace update after upload

    <property name="alternatedocroot_1" value="from=/uploads/* dir=/var/webapp" />
    
    And use http://localhost:8080/contextname/uploads/* to serve those uploaded images from by 
    
    <h:graphicImage> the usual way. 
    

    Without other inner folders like

    stefano/Documenti/UniLife/avatar/

    And have you changed you’re bean code ?

    File imageFile = new File(extContext.getRealPath("NEW//uploaded//temp") + "//" + utente.getUsername() + ".png");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

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.