[solved] Dynamic number of ‘/’ characters

Splash Forums PrettyFaces Users [solved] Dynamic number of ‘/’ characters

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

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • #17757



    I know that the answer to my question is in FAQ and in documentation, but i think i’ve tried everything and it still doesn’t work – probably because my knowledge about regular expressions is not enough. My problem is that I’m passing some dynamic number of parameters splited by a delimiter ‘/’, In preety faces 2.x it was easy and I just needed to make a ‘.*’ at the and of a pattern – i.e: /search/.*, and than just go to some function and parse whole URL, by getting it from PrettyContext. In PrettyFaces 3 I don’t know how to do it, how to get whole query with slashes ‘/’ that starts at some point and write it to variable that will be processed. I’m looking for smt like <pattern>search#{ /[w:/]+/ someBean.somevariable}/

    That will accept link like search/q:smth1/p:/smth2/ …. And so on …

    Any help? Many thanks in advance




    I am searching for the same, i mapped everything beginning with /intranet/

    to a single JSF ViewId with PrettyFaces 1.2.6 using JSF 1.2.

    How is it possible with 3.0.1 ?


    Hi guys. It should still work the same way in PrettyFaces 3 – Except the API for accessing the URL has changed.

    URL url = PrettyContext.getCurrentInstance().getRequestURL();
    QueryString query = PrettyContext.getCurrentInstance().getRequestQueryString();

    But voltman, your pattern is wrong :) use something like this instead:

    <pattern>/search/#{ /.*/ someBean.somevariable}/</pattern>

    bomadil, does this answer your question?




    The pattern like you provided:

    <pattern>/search/#{ /.*/ someBean.somevariable}/</pattern>

    was my first shot and it’s doesn’t work on links like:

    search/q:smth1/p:smth2/ – 404 error

    where it still does work for

    search/q:smth1/ – OK

    My frist thought was that it natuarlly breaks at ‘/’ sign as u pointed that in documntation, so i’ve tried different greedy patterns that include the magic slash sign but they did fail aswell. So that is why I’m asking


    Interesting… could you send me your configuration so I can try to reproduce? Thanks.



    Yea sure… this is part of pretty-config.xml:

    <!--       <url-mapping id="paramSearch0">
    <pattern>/search/s/#{ /.*/ searchParamBean.searchQuery}/</pattern>

    <url-mapping id="paramSearch1">

    <url-mapping id="paramSearch2">

    <url-mapping id="paramSearch3">

    <url-mapping id="paramSearch4">
    <pattern>/search/s/#{query: searchParamBean.searchQuery}/#{city: searchParamBean.searchQuery}/#{employer: searchParamBean.searchQuery}/#{region: searchParamBean.searchQuery}/</pattern>

    <url-mapping id="paramSearch5">
    <pattern>/search/s/#{query: searchParamBean.searchQuery}/#{ city: searchParamBean.searchQuery}/#{employer: searchParamBean.searchQuery}/#{region: searchParamBean.searchQuery}/#{page: searchParamBean.searchQuery}/</pattern>

    – yes i know that this solution is nasty, but this is working for me now, the best way would be to use commented solution at the top marked with id “paramSearch0”.

    SearchParamBean is class made just for purpose of parsing url, geting search params and passing them to appropriete beans. Normally using pattern like <pattern>/search/s/#{ /.*/ searchParamBean.searchQuery}/</pattern> I would get all the params easily in one variable. Since this doesnt work form me I have to do the trick with setter and getter methods for variable searchQuery

    SearchParamBean class methods:

    public String getSearchQuery() {
    return searchQuery;

    public void setSearchQuery(String searchQuery) {
    this.searchQuery = searchQuery;
    this.searchQuery += ";" + searchQuery;

    public String parseURL(){
    String returnURL = null, orgURL = null;
    Map<String, String> paramMap = new HashMap<String, String>();
    orgURL = PrettyContext.getCurrentInstance().getContextPath();

    String [] paramArray = null, tParamArray = null, ttParamArray = null;

    paramArray = searchQuery.split(";");

    for(String param: paramArray){
    tParamArray = param.split("/");
    for(String ttParam : tParamArray){
    ttParamArray = ttParam.split(":");
    if(ttParamArray != null && ttParamArray.length > 1)
    paramMap.put(ttParamArray[0], ttParamArray[1]);

    ELContext elContext = FacesContext.getCurrentInstance().getELContext()
    SearchBean searchBean = (SearchBean) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "searchBean");

    CityBean cityBean = (CityBean)FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "cityBean");


    returnURL= "/faces/pages/search.xhtml";
    return returnURL;

    At the end application should accept links like ../search/s/q:something1/c:something2/e:something2/r:something3/p:0/

    If you need anythink else please tell :)


    Congratulations, you found a bug. I’m working on patching it, but am on vacation right now. For the moment, you can do this instead:

    “In pretty faces 2.x it was easy and I just needed to make a ‘.*’ at the and of a pattern – i.e: /search/.*, and than just go to some function and parse whole URL, by getting it from PrettyContext.”

    Do the same thing. Just call different methods from PrettyContext:

    String url = PrettyContext.getCurrentInstance().getRequestURL().getDecodedURL();
    String query = PrettyContext.getCurrentInstance().getRequestQueryString().toString();




    Ok, this should be fixed in the trunk now. Try the latest 3.0.2-SNAPSHOT (you might have to get it from the OcpSoft repository until it syncs with maven central.)

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

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

Comments are closed.