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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:17:53+00:00 2026-05-31T05:17:53+00:00

I hope I get this one straight: I try to create an JSF 2.0

  • 0

I hope I get this one straight:

I try to create an JSF 2.0 Page optimized for mobile use on Tomcat 7. Therefore I use Mojarra 2.1.6 and PrimeFaces (Core 3.1.1 and Mobile 0.9.1).

My scenario:

  1. User visits simplified URL, e.g. http://www.someurl.eu/view.xhtml/12345678
  2. ServletFilter rewrites Url to http://www.someurl.eu/view.xhtml?id=12345678
  3. Url Parameter gets provided to ManagedBean
  4. Necessery Data gets evaluated and published to my view.xhtml
  5. On my view.xhtml a button for download is provided

My problem:

By clicking the button the server shows me a NPE when the ManagedBean is set to @RequestScoped.
My assumption is that by clicking the button a new request is fired, my URL-parameter gets lost and the download file is not available anymore.
I don’t know if I’m right but if so I don’t know how to solve this one elegant.

My ManagedBean:

@ManagedBean
@RequestScoped
public class ViewBean {

// Elements
...
private StreamedContent file;
...

// Getter and Setter
...
public StreamedContent getFile() {
    invalidateSession();
    return file;
}
public void setFile(StreamedContent file) {
    this.file = file;
}
...

// Init
@PostConstruct
public void init() {

    //read URL-Parameter
    urlSdbac = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");

    // validate
    if(urlSdbac == null || urlSdbac.equals("") || urlSdbac.length() != 8) {
        urlSdbac = "invalid";
    }
    // get Data
    else {
        SdbCustomerData cd = getFileMetadata(urlSdbac);

        if(cd == null) {
            this.name = "invalid code";
            this.language = "no language options found";
        }
        else {
            ...
            // prepare File for Download
            this.file = new Helper().getWebDavFile(cd.getCid(), cd.getName());
        }
    }
}

My view.xhtml:

<h:form>  
  <pm:page title="Download">
    <pm:view>
        <pm:content>
        ...
            <p:commandButton  value="Download" ajax="false">
                    <p:fileDownload value="#{viewBean.file}" />
            </p:commandButton>
        </pm:content>
    </pm:view>
  </pm:page>
</h:form>

Last but not least, my Filter:

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    String url = request.getRequestURI();

    Pattern sdbac = Pattern.compile("[A-Za-z0-9]{8}");
    Matcher fit = null;

    // check Page
    if(url.contains("view.xhtml/") && (!url.contains("?id=") && !url.endsWith("view.xhtml")) ) {
        String code = url.substring(url.indexOf("view.xhtml/")+11, url.length());
        // validate Param?
        fit = sdbac.matcher(code);
        if(fit.matches()) {
            // redirect
            response.sendRedirect("/getSDS/view.xhtml?id=" + code);
        }
        else {
            // redirect
            response.sendRedirect("/getSDS/view.xhtml?id=invalid");
        }
    }
    else {
        chain.doFilter(req,res);
    }
} 

My Filter is mapped to any URL <url-pattern>/*</url-pattern>

I’ve also tried to set the ManagedBean to @SessionScoped. If I do so the download works fine but the user isn’t able to change the URL because of the persitent data in the session scoped ManagedBean.

Maybe I’m too blind to see the obvious solution.

Any help would be appreciated! Thanks in advance!

P.S.
The exception

java.lang.NullPointerException
org.primefaces.component.filedownload.FileDownloadActionListener.processAction(FileDownloadActionListener.java:58)
javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
javax.faces.component.UICommand.broadcast(UICommand.java:300)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
eu.qualisys.getsds.filter.SDBACParamFilter.doFilter(SDBACParamFilter.java:53)
  • 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-05-31T05:17:54+00:00Added an answer on May 31, 2026 at 5:17 am

    Use the view scope.

    @ManagedBean
    @ViewScoped
    

    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

Hope to get solution to this problem. I have been stuck on it since
hope to get some help here because this is something that really makes me
EDIT: I've tagged this C in a hope to get more response. It's more
(Hope this doesn't get duplicated; second attempt at submitting this question) I'm working on
My hope is to one-click a shortcut, and get a grid of cygwin shells
Hope anyone can shed light on this so I can use pens with dash
hope you can help me on this one, I'm currently using this: jQuery plugin:validation
I'm trying to get this to work and I hope this isn't too vague.
I hope you guys can help me with this one. So, I have a
I just ran into this one and couldn't seem to get any clear answer

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.