pretty url broken

Splash Forums PrettyFaces Users pretty url broken

This topic contains 5 replies, has 2 voices, and was last updated by  Christian Kaltepoth 4 years, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #27577



    I got problem to show view page with pretty url after submit the form for saving data.

    after submit form, I navigate to view page using url no 2(actual) using ‘externalContext.redirect()’.

    1. edit page edit/PBB/8123

    2. after save & redirect ->
    expected: view/PBB/8123
    actual : view.xhtml?publicationId=8123&pubCategoryCode=PBB&faces-redirect=true




    Please share your configuration, which dependencies your are using and the relevant parts of your code.




    Please see code snipped. thx

    <url-mapping parentId="ilibrary" id="publication-edit">
    	<pattern value="/edit/#{pubCategoryCode}/#{publicationId}" />
    	<view-id value="/pages/protected/isralib/publication/edit.xhtml" />
    <url-mapping parentId="ilibrary" id="publication-view">
    	<pattern value="/view/#{pubCategoryCode}/#{publicationId}" />
    	<view-id value="/pages/public/isralib/publication/view.xhtml" />
    <h:form id="edit" enctype="multipart/form-data">
    	<p:commandButton value="#{msg['']}"
    				 ajax="false" styleClass="GreenButton">
    		<f:param name="pubCategoryCode" value="PBB"/>
    save() {
    	FacesContext facesContext = FacesContext.getCurrentInstance();
    	ExternalContext externalContext = facesContext.getExternalContext();
    	HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
    	String url = request.getRequestURL().toString().replace(request.getRequestURI().substring(0), "") + request.getContextPath();
    	String path = "/pages/public/isralib/publication/view.xhtml?publicationId=8123&pubCategoryCode=PBB&faces-redirect=true";
    	try {
    	    externalContext.redirect(url + path);
    	} catch (IOException e) {
    	    getLogger().error("Redirect failed", e);

    Why are you using this weird way of redirecting via ExternalContext? Why not just:

    return "/pages/public/isralib/publication/view.xhtml?publicationId=8123&pubCategoryCode=PBB&faces-redirect=true";


    because I’m using actionListener=”#{}”.

    of course there is lots of operation in the save method.

    i just put a snipped of code


    I guess you need something like this:

    String rewritten = externalContext.encodeRedirectURL( path, new HashMap<>() );
    externalContext.redirect(url + rewritten);

    Outbound URLs are rewritten using HttpServletResponse.encodeRedirectURL(), so if you are doing redirects manually, you will have to call this method yourself.

    BTW: I think you don’t need url in your code. Just do:

    externalContext.redirect(request.getContextPath() + rewritten);
Viewing 6 posts - 1 through 6 (of 6 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.