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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:06:56+00:00 2026-06-11T03:06:56+00:00

I can’t get the preRenderView event listener to work on a GET request in

  • 0

I can’t get the preRenderView event listener to work on a GET request in JSF 2.1.

I have found a lot about it but nothing seems to work e.g.:
Conditional redirection in JSF
http://andyschwartz.wordpress.com/2009/07/31/whats-new-in-jsf-2/#get-prerenderview-event
http://developer.am/j2eetutorial/jsf/?page=jsf-2-prerenderviewevent-example
JSF, Spring, and the PreRenderViewEvent
http://balusc.blogspot.dk/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters

I have a template with 4 insert blocks and I have tried to insert the event code at all those places but without any luck. I have tried both with and without the f:metadata tag surrounding it.

<f:event type="preRenderView" listener="#{applicationData.redirectIfNoResults}" />

Bean:

@ManagedBean
@ApplicationScoped
public class ApplicationData implements Serializable {
    public void redirectIfNoResults() throws IOException { 
        if (getTotal() < 1) { 
            ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); 
            ec.redirect(ec.getRequestContextPath() + "/noResults.xhtml"); 
        } 
    } 
    ...
}

Template:

<?xml version='1.0' encoding='UTF-8' ?>
<!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">
    <ui:insert name="beforeHeader" />
    <f:view>
        <ui:insert name="inView" />
    </f:view>
    <h:head>
        <meta http-equiv="cache-control" content="no-store" />
        <link href="style.css" rel="stylesheet" type="text/css" />
        <title>Quick Poll</title>
        <ui:insert name="header" />
    </h:head>
    <h:body>
        <h1>Quick Poll</h1>
        <ui:insert name="content" />
    </h:body>
</html>

View:

    <ui:define name="content">
        #{applicationData.question}?<p/>
        <h:panelGrid columns="3" border="0">
                Yes: 
                <h:panelGrid bgcolor="black" height="20" width="#{300*applicationData.yes/applicationData.total}"/>
                #{applicationData.yes}
                <h:outputText value="No:"/> 
                <h:panelGrid bgcolor="black" height="20" width="#{300*applicationData.no/applicationData.total}"/>
                #{applicationData.no}
        </h:panelGrid>
    </ui:define>
</ui:composition>

Please help me figure out how to get it working..

Update 1:
I have made changes as suggested by BalusC but it is still not working..

Template:

<?xml version='1.0' encoding='UTF-8' ?>
<!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">
    <h:head>
        <meta http-equiv="cache-control" content="no-store" />
        <link href="style.css" rel="stylesheet" type="text/css" />
        <title>Quick Poll</title>
        <ui:insert name="header" />
    </h:head>
    <h:body>
        <h1>Quick Poll</h1>
        <ui:insert name="content" />
    </h:body>
</html>

View:

<?xml version='1.0' encoding='UTF-8' ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:f="http://java.sun.com/jsf/core"
     template="template.xhtml">
    <ui:define name="content">
        <f:event listener="#{applicationData.redirectIfNoResults}" type="preRenderView"></f:event> 
        #{applicationData.question}?<p/>
        <h:panelGrid columns="3" border="0">
                Yes: 
                <h:panelGrid bgcolor="black" height="20" width="#{300*applicationData.yes/applicationData.total}"/>
                #{applicationData.yes}
                <h:outputText value="No:"/> 
                <h:panelGrid bgcolor="black" height="20" width="#{300*applicationData.no/applicationData.total}"/>
                #{applicationData.no}
        </h:panelGrid>
    </ui:define>
</ui:composition>
  • 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-11T03:06:58+00:00Added an answer on June 11, 2026 at 3:06 am

    I ended up making a solution with a PostConstruct method in a view scope bean.
    Like this: Initializng a Backing Bean With Parameters on Page Load with JSF 2.0

    Bean:

    @ManagedBean 
    @ViewScoped
    public class ResultsController {
        @ManagedProperty(value="#{applicationData.total}")  
        private int total; 
        @ManagedProperty(value="#{applicationData.yes}")  
        private int yes; 
        @ManagedProperty(value="#{applicationData.no}")  
        private int no; 
    
        @PostConstruct 
        public void postConstruct() {
            if (getTotal() < 1) { 
                ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext(); 
                try {
                    ec.redirect(ec.getRequestContextPath() + "/noResults.jsf");
                } catch (IOException e) {
                    System.out.println("noResults.jsf redirect failed.");
                    e.printStackTrace();
                } 
            } 
        }
        ...
    }
    

    View:

    <?xml version='1.0' encoding='UTF-8' ?>
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        xmlns:f="http://java.sun.com/jsf/core"
         template="template.xhtml">
        <ui:define name="content">
            #{applicationData.question}?<p/>
            <h:panelGrid columns="3" border="0">
                    Yes: 
                    <h:panelGrid bgcolor="black" height="20" width="#{300*resultsController.yes/resultsController.total}"/>
                    #{resultsController.yes}
                    <h:outputText value="No:"/> 
                    <h:panelGrid bgcolor="black" height="20" width="#{300*resultsController.no/resultsController.total}"/>
                    #{resultsController.no}
            </h:panelGrid>
        </ui:define>
    </ui:composition>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Can't figure out how to do this in a pretty way : I have
Can someone please explain why this doesn't work? MyClass myClass1 = new MyClass(); object
This could be a duplicate question, but I have no idea what search terms
Can anyone tell me why this doesn't work? <?php $lang = $_get[lang]; if (($lang
Can some one Guide me to work with these things... What is Model popup
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can't work out a way to make an array of buttons in android. This
Can i get the source code for a WAMP stack installer somewhere? Any help
Can somebody point me to a resource that explains how to go about having

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.