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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:40:50+00:00 2026-05-17T22:40:50+00:00

I have a web-application where the users can be sent directly to some specific

  • 0

I have a web-application where the users can be sent directly to some specific pages (such as a page where he can view or edit an item). To achieve that, we provide a specific url. These urls are located outside the current web-application (i.e. they can be present in another web-application, or in an email).

The url looks like http://myserver/my-app/forward.jsf?action=XXX&param=YYY, where:

  • action represents the page where the user will be redirected. You can consider this as the from-outcome of any JSF action in navigation-case in faces-config.xml.
  • actionParam is a parameter for the previous action (generally an item ID)

So for example, I can have these kind of urls:

  • http://myserver/my-app/forward.jsf?action=viewItem&actionParam=1234
  • http://myserver/my-app/forward.jsf?action=editItem&actionParam=1234

Of course, I have a Java class (bean) that will check some security constraints (i.e. is the user allowed to see / edit the corresponding item?) and then redirect the user to the correct page (such as edit.xhtml, view.xhtml or access-denied.xhtml).


Current implementation

Currently, we have a basic way to accomplish the forward. When the user clicks on the link, the following XHTML page is called:

<html>
    <body id="forwardForm">
        <h:inputHidden id="myAction" binding="#{forwardBean.hiddenAction}"/>
        <h:inputHidden id="myParam" binding="#{forwardBean.hiddenActionParam}"/>
        <h:commandButton id="forwardBtn" actionListener="#{forwardBean.doForward}" style="display: none;"/>
    </body>
    <script type="text/javascript">
        document.getElementById('forwardForm:forwardBtn').click();
    </script>
</html>

As you can see, I bind two <h:inputHidden> components in my Java bean. They will be used to store the value of both action and actionParam request parameter (using FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("actiontParam");). I also provide the doForward method that which will be called immediately when the page is rendered, which will redirect (again) the user to the real page. The method is:

public void doForward(ActionEvent evt) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    String redirect = // define the navigation rule that must be used in order to redirect the user to the adequate page...
    NavigationHandler myNav = facesContext.getApplication().getNavigationHandler();
    myNav.handleNavigation(facesContext, null, redirect);
}

This solution is working, but I have two problems with that:

  • I don’t like the way it is implemented. I’m sure that I can have something simplier (using a Servlet?).
  • This solution is using Javascript, and I must not use Javascript (as this forward may be used by old Blackberry users, where the Javascript is not supported).

So my question is how to refactor this redirection / forward feature?

Technical information

Java 1.6, JSF 1.2, Facelets, Richfaces

  • 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-17T22:40:50+00:00Added an answer on May 17, 2026 at 10:40 pm

    Set the GET query parameters as managed properties in faces-config.xml so that you don’t need to gather them manually:

    <managed-bean>
        <managed-bean-name>forward</managed-bean-name>
        <managed-bean-class>com.example.ForwardBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>action</property-name>
            <value>#{param.action}</value>
        </managed-property>
        <managed-property>
            <property-name>actionParam</property-name>
            <value>#{param.actionParam}</value>
        </managed-property>
    </managed-bean>
    

    This way the request forward.jsf?action=outcome1&actionParam=123 will let JSF set the action and actionParam parameters as action and actionParam properties of the ForwardBean.

    Create a small view forward.xhtml (so small that it fits in default response buffer (often 2KB) so that it can be resetted by the navigationhandler, otherwise you’ve to increase the response buffer in the servletcontainer’s configuration), which invokes a bean method on beforePhase of the f:view:

    <!DOCTYPE html>
    <html xmlns:f="http://java.sun.com/jsf/core">
        <f:view beforePhase="#{forward.navigate}" />
    </html>
    

    The ForwardBean can look like this:

    public class ForwardBean {
        private String action;
        private String actionParam;
    
        public void navigate(PhaseEvent event) {
            FacesContext facesContext = FacesContext.getCurrentInstance();
            String outcome = action; // Do your thing?
            facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, null, outcome);
        }
    
        // Add/generate the usual boilerplate.
    }
    

    The navigation-rule speaks for itself (note the <redirect /> entries which would do ExternalContext#redirect() instead of ExternalContext#dispatch() under the covers):

    <navigation-rule>
        <navigation-case>
            <from-outcome>outcome1</from-outcome>
            <to-view-id>/outcome1.xhtml</to-view-id>
            <redirect />
        </navigation-case>
        <navigation-case>
            <from-outcome>outcome2</from-outcome>
            <to-view-id>/outcome2.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>
    

    An alternative is to use forward.xhtml as

    <!DOCTYPE html>
    <html>#{forward}</html>
    

    and update the navigate() method to be invoked on @PostConstruct (which will be invoked after bean’s construction and all managed property setting):

    @PostConstruct
    public void navigate() {
        // ...
    }    
    

    It has the same effect, however the view side is not really self-documenting. All it basically does is printing ForwardBean#toString() (and hereby implicitly constructing the bean if not present yet).


    Note for the JSF2 users, there is a cleaner way of passing parameters with <f:viewParam> and more robust way of handling the redirect/navigation by <f:event type="preRenderView">. See also among others:

    • Hit a bean method and redirect on a GET request
    • Is there any easy way to preprocess and redirect GET requests?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web application with users and their documents. Each user can have
I have a web application where users enter arbitrary sql queries for later batch
I have a web-based application that notifies users of activity on the site via
I have a web application that should behave differently for internal users than external
We have a web application that periodically sends out e-mails to users. At the
We have created a web application, using ASP.NET, that allows users to upload documents
Our web application sends e-mails. We have lots of users, and we get lots
I have a scenario where users of my ASP.NET web application submit testimonials consisting
I have a web application that uses Ext-JS 2.2. In a certain component, we
I have a web application that uses the current version of JQuery that needs

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.