[solved] Handling extra long set of query parameters

Splash Forums PrettyFaces Users [solved] Handling extra long set of query parameters

This topic contains 6 replies, has 2 voices, and was last updated by  Lincoln Baxter III 7 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17754

    tdruttenberg
    Participant

    Hi,

    We are interested in using prettyfaces to solve a problem we have with out website. Can someone give me an idea of where to begin?

    The basic problem is the application can take up to something like 20 query parameters, most of which are empty when the page is rendered. We would like to somehow get rid of all those empty parameters and only display in the URL the parameters that have a value.

    For example, take a URL like this

    http://ond.ssa.gov/ONDList.seam?hostname=colum&state=&city=&oob=&address=&zip=21215&platform=&cid=7

    And end up with this

    http://ond.ssa.gov/ONDList.seam?hostname=colum&zip=21215&cid=7

    Can we do this with prettyfaces? Should we do this with prettyfaces?

    Tanya

    #19993

    You most certainly can do this :) And it can also be done globally or per-URL-mapping if desired.

    You should take a look at the custom URL processor feature (which is new in the 3.0.x series.)

    http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html/inbound_rewriting.html#inbound_rewriting.options

    You’d create a rewrite rule like this:

    <rewrite match="..." processor="gov.ssa.ond.url.processor.RemoveEmptyParams" redirect="301" />

    Your processor would look something like this:

    package gov.ssa.ond.url.processor;

    public class RemoveEmptyParams implements Processor {

    public String process(final RewriteRule rewrite, final String url) {
    return url.replaceAll("\w+=[&]?+", "");
    }
    }

    The pattern I’ve used in the replacement might not be exactly correct, but it will look something like that.

    #19994

    The match="..." would need to be filled in with a pattern that matched URLs you wanted to be rewritten.

    #19995

    For a more general idea of how to install prettyfaces, read the installation chapter of the reference guide (not yet published, but is available):

    http://ocpsoft.com/docs/prettyfaces/snapshot/en-US/html_single/#GettingStarted

    #19996

    tdruttenberg
    Participant

    Thank you Lincoln! I figured it wouldn’t be hard, just had no clue how to begin. I will give it a shot. I already got PrettyFaces installed. It was quite easy.

    TDR

    #19997

    tdruttenberg
    Participant

    Lincoln, the code you posted in my other other posting about the ClassCastException works just fine.

    FTR here it is

    public class RemoveEmptyParams implements Processor

    {

    public String process(final RewriteRule rule, final String url)

    {

    String result = url.replaceAll(“\?[^=]+=&”, “?”);

    result = result.replaceAll(“&[^=]+=&”, “&”);

    result = result.replaceAll(“&[^=]+=$”, “”);

    return result;

    }

    }

    I’m all set now. Thanks!

    #19998

    Thank you TDR! :)

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

You must be logged in to reply to this topic.

Comments are closed.