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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:27:27+00:00 2026-05-16T03:27:27+00:00

This is my jsf code :- <h:commandButton id=cmdLogin value=Login actionListener=#{indexBean.login}> <f:ajax execute=@form render=@all />

  • 0

This is my jsf code :-

  <h:commandButton id="cmdLogin" value="Login" actionListener="#{indexBean.login}">
                            <f:ajax execute="@form" render="@all" />
                        </h:commandButton>

This is my login method of indexBean :-

 public void login(){

                HttpServletResponse objHttpServletResponse = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
                objHttpServletResponse.sendRedirect("Restricted/Home.jsf");

    }

I get one alert in javascript emptyResponse: An empty response was received from the server. Check server error logs.. Why does this type of redirect not work?

EDIT :-
Interestingly, when i redirect from faces-config.xml, it works!

<faces-config version="2.0"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">

    <navigation-rule>
        <from-view-id>/index.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>Home</from-outcome>
            <to-view-id>/Restricted/Home.jsf</to-view-id>
            <redirect/>
        </navigation-case>
    </navigation-rule>

</faces-config>

And obviously, i changed actionListener of commandbutton to action and changed return type of login to String and returned home from login method. Can anybody tell now, if this is the desired behaviour in JSF ? How come redirect from faces-config.xml works and simple redirect in managedbean doesn’t?

  • 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-16T03:27:28+00:00Added an answer on May 16, 2026 at 3:27 am
    HttpServletResponse objHttpServletResponse = (HttpServletResponse)
                                  FacesContext.getCurrentInstance()
                                              .getExternalContext()
                                              .getResponse();
    objHttpServletResponse.sendRedirect("Restricted/Home.jsf");
    

    Here, you leave the JSF API and cast down to the servlet API where JSF will not handle anything you do. When you invoke this method, the server returns a 302 response instead of the AJAX response the JavaScript API was expecting.

    The correct mechanism to perform a programmatic redirect in JSF is to use the ExternalContext:

    FacesContext.getCurrentInstance()
                .getExternalContext()
                .redirect("yourUrl");
    

    If you use this mechanism with an AJAX call in JSF 2.0, the server will send a response like this:

    <?xml version="1.0" encoding="utf-8"?>
    <partial-response><redirect url="yourUrl"></redirect></partial-response>
    

    You can use tools like Firebug and Fiddler to inspect your server’s responses.


    Note that this method signature is incorrect: public void login(). The specification states that action methods must declare an object return type (the fact that your implementation doesn’t throw an error just means you got lucky).

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

Sidebar

Related Questions

Consoder the following code: <h:commandButton value=do action=#{testBacking.do}> <f:ajax execute=@all render=@all listener=#{testBacking.listener}/> </h:commandButton> I want
I was trying something like below -- <h:commandButton id=btnOK> <f:ajax event=action execute=@this render=idHeader listener=#{myBean.actionSubmit()}/>
JSF view code: <f:view> <h:form> <h:panelGrid> <h:inputText id=key value=#{myManagedBean.key}/> <h:selectBooleanCheckbox id=rerun value=#{myManagedBean.rerun} rendered=#{myManagedBean.displayRerun}/> <h:commandButton
I've been read this article : commandButton/commandLink/ajax action/listener method not invoked or input value
I have JSF code like: <h:inputText id=from value=#{fromToMBean.fromName}/> I would like to get this
I have the following code inside a method invoked by a jsf <h:commandButton>. It
This is the complete source code: http://www.sendspace.com/file/lwxpyf I have a problem with a JSF
I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
Before going on, see this question It's JSF form is shown again as follows:
i'm trying to implement a very basic (at this point) login screen with JSF

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.