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 7945267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:48:36+00:00 2026-06-04T00:48:36+00:00

I’ve got multiple pages that allow the download of the same resource (retrieved from

  • 0

I’ve got multiple pages that allow the download of the same resource (retrieved from my DB).

The problem is that the download works just on some of them, even with the SAME code and calling the SAME bean.

This thing is getting quite annoying because, on the non working pages, clicking on the download link will just reload the page without any message/exception, so I can’t find out what’s happening.

Here’s my BEAN code :

package ManagedBeans;

import ejb.DispensaManagerLocal;
import entity.Dispensa;
import entity.Utente;
import java.io.ByteArrayInputStream;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import org.primefaces.event.RateEvent;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

/**
 *
 * @author stefano
 */
@ManagedBean
@RequestScoped
public class DispensaBean {

    @EJB
    private DispensaManagerLocal dispensaManager;
    @ManagedProperty(value = "#{loginBean.utente}")
    private Utente utente;

    public Utente getUtente() {
        return utente;
    }

    public void setUtente(Utente utente) {
        this.utente = utente;
    }

    /**
     * Creates a new instance of DispensaBean
     */
    public DispensaBean() {
    }

    public StreamedContent getDownload() {
        String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("dispensaId");        
        System.out.println("________" + id);
        Dispensa d = dispensaManager.findById(Integer.parseInt(id));        
        String type = getMimeFromByte(d.getDatiFile());
        String estensione = "";
        if(type.equals("application/pdf")){
            estensione = ".pdf";
        } else if(type.equals("application/zip")) {
            estensione = ".zip";
        } else if(type.equals("application/vnd.ms-powerpoint")) {
            estensione = ".ppt";
        }        
        return new DefaultStreamedContent(new ByteArrayInputStream(d.getDatiFile()), type, d.getTitolo() + estensione);
    }


    private String getMimeFromByte(byte[] src) {
        if (src[0] == 0x25 && src[1] == 0x50 && src[2] == 0x44 && src[3] == 0x46) {
            return "application/pdf";
        }
        if (src[0] == 0x50 && src[1] == 0x4b) {
            return "application/zip";
        }
        if (src[0] == 0xd0 && src[1] == 0xcf && src[2] == 0x11 && src[3] == 0xe0 && src[4] == 0xa1 && src[5] == 0xb1 && src[6] == 0x1a && src[7] == 0xe1) {
            return "application/vnd.ms-powerpoint";
        }
        return "application/octet-stream";
    }

}

Now, on the NON working pages, the getDownload() method is NOT called, as it doesn’t print anything.

Here’s the download button code

<h:form style="float: right">
    <pou:commandLink id="downloadDispensa" ajax="false" disabled="#{!loginBean.logged}">
       <pou:graphicImage value="./resources/images/download.png" height="30"/>
       <pou:fileDownload value="#{dispensaBean.getDownload()}"/>                                                    
       <f:param name="dispensaId" value="#{dispensa.id}"/>
    </pou:commandLink>                                
</h:form> 

What I’ve noticed is that the download link just RELOADS the page instead of calling the method, and this happens only in the pages in which #{dispensa.id} depends on a GET parameter.

For example, I’ve got a page called dispensa.xhtml that displays all my files in the DB if no GET parameters are passed.

Indeed, dispensa.xhtml?id=5 will display just the file with id=5.

Clicking on the download link, in the first case, works without problems.
Doing it in the second case will reload the page and will lose the GET parameter, so the it will load dispensa.xhtml instead of dispensa.xhtml?id=5.

I’d think that there’s some problem in using the GET parameter, but..yesterday it WORKED and I did NOT change this code!

The other NON working page is ricerca.xhtml which shows the (multiple) results of a query given by ricerca.xhtml?key=query.

Finally, to mess things up, the download in profile.xhtml?user=username WORKS.

This destroys my whole theory about GET parameters.

To avoid having a null byte[] datiFile, I’ved edited my Dispensa entity this way :

@Basic(optional = true, fetch=FetchType.EAGER)
@Lob
@Column(name = "datiFile")    
private byte[] datiFile;

I don’t know what to do because it doesn’t say what’s going wrong, it just reloads the page, bypassing my download!

EDIT :

I’ve tried changing my getDownload() method to return a File which is on my HD, to understand if the problem is caused by a null data on the db but it still doesn’t work as I said!

  • 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-04T00:48:38+00:00Added an answer on June 4, 2026 at 12:48 am

    Seems that I solved this by using an alternative solution.

    I’ve changed all

    <h:form style="float: right">
            <pou:commandLink id="downloadDispensa" ajax="false" disabled="#{!loginBean.logged}">
               <pou:graphicImage value="./resources/images/download.png" height="30"/>
               <pou:fileDownload value="#{dispensaBean.getDownload()}"/>                                                    
               <f:param name="dispensaId" value="#{dispensa.id}"/>
            </pou:commandLink>                                
        </h:form> 
    

    to

    <h:form style="float: right">
        <h:outputLink id="downloadDispensa" disabled="#{!loginBean.logged}" target="_blank" value="./download.xhtml?id=#{dispensa.id}">
             <pou:graphicImage value="./resources/images/download.png" height="30"/>                                    
         </h:outputLink>                                
    </h:form>
    

    where download.xhtml has this code :

    <script type="text/javascript">
        if(document.referrer == "" || document.referrer == "download.xhtml"){
            self.location='./index.xhtml';
        }
        document.onblur = new Function('self.close()');
    </script>
    <h:body onload="document.getElementsByClassName('downloadDispensa')[0].click();" rendered="#{loginBean.logged}">
        <h:form>            
            <h:commandLink class="downloadDispensa" id="downloadDispensa" style="display: none">                
                <pou:graphicImage value="./resources/images/download.png" height="30"/>
                <pou:fileDownload value="#{dispensaBean.download}"/>                                                                                       
                <f:param name="dispensaId" value="#{request.getParameter('id')}"/>
            </h:commandLink> 
        </h:form>        
    </h:body>
    <h:body onload="self.location='./index.xhtml';" rendered="#{!loginBean.logged}">
    </h:body>
    

    So it loads the download page, autoclicks on the download link and it autocloses the page when the download dialog is shown.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.