Losing request parameter

Splash Forums PrettyFaces Users Losing request parameter

This topic contains 1 reply, has 2 voices, and was last updated by  Christian Kaltepoth 1 year, 10 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #26421

    myr
    Participant

    Hello,

    Well on page1.xhtml I have a commandButton which send a parameter :

    <h:commandButton value="submit" action="#{loginController.changepage}" icon="ui-icon-check">
    			<f:param name="login" value="mylogin" />
    			</h:commandButton>

    On click it goes to controller method which simply return page2.xhtml with prettyfaces.

    public String changepage(){
    		return "pretty:login";	
    }

    (the controller is in requestScoped and prettyfaces is 3.3.3)

    On page2.xhtml I display the login from controller

    <h:outputText value="#{loginController.login}" />

    Controller :

    	public String getLogin(){
    		FacesContext context = FacesContext.getCurrentInstance();
    		Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
    		String login = requestMap.get("login");
    	return login;
    	}

    Here login is null. The request parameter seems to be lost.

    However when I remove pretty and use classic forward

    Instead of

    public String changepage(){
    		return "pretty:login";	
    	} 

    I put

    public String changepage(){
    		return "page2.xhtml";	
    	}

    Then the parameter is kept and correctly displayed on page2.

    I can’t figure out why pretty returns null for my request parameter.
    Somebody has already explained me but I need more explications.
    Could you explain me why?

    Thanks.

    • This topic was modified 1 year, 10 months ago by  myr.
    • This topic was modified 1 year, 10 months ago by  myr.
    #26427

    If you use:

    return "pretty:login";

    PrettyFaces will send a redirect to the client, which means that the browser will request page2 in a separate request. That’s why the parameter is lost.

    If you use:

    return "page2.xhtml";

    JSF will directly render page2 in the SAME request. That’s why the URL won’t change and you will still have page1 in the browser URL. But as it is the same request, the parameter will be still there.

    If you force JSF to also use a redirect by using:

    return "page2.xhtml?faces-redirect=true";

    You will actually have the same problem.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.