parameter special characters are converting into junk characters.

Splash Forums PrettyFaces Users parameter special characters are converting into junk characters.

This topic contains 19 replies, has 2 voices, and was last updated by  Carolina 4 years, 7 months ago.

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • #18804

    Carolina
    Member

    Hi Pretty,

    I have used URL rewrite with parameters as follows.

    <url-mapping id=”flightPlusHotel”>

    <pattern value=”/vacation-packages/search?#{urlHandlerBean.vacationsUrlParams}” />

    <view-id value=”/pages/package/flighthotel/flightPlusHotelResults.xhtml” />

    </url-mapping>

    In browser the ‘?’ character is replacing with ‘%3F’ because of this, ‘ is not available ‘ error page is showing.

    ( http://e125:8080/b2c/vacation-packages/search%3Ftrip=R&origin1=RUH&destination1=JED&depart_date=31/10/2012&arrival_date=07/11/2012&type=D&room1=1A-0C-0I )

    How to use ? in the parameters URL rewriting.

    And

    Can I access these parameters from the request.getParameter(“origin1”) in backend?

    #23097

    Your pattern looks very strange. PrettyFaces expects a plain path without a query string here. Therefore the pattern part is URL encoded when outgoing URLs are created.

    Why don’t you use <query-param> instead?

    <url-mapping id="flightPlusHotel">
    <pattern value="/vacation-packages/search" />
    <query-param name="trip"> #{someBean.trip} </query-param>
    <query-param name="origin1"> #{someBean.origin1} </query-param>
    <query-param name="destination1"> #{someBean.dest1} </query-param>
    <!-- .... -->
    <view-id value="/pages/package/flighthotel/flightPlusHotelResults.xhtml" />
    </url-mapping>

    See:

    http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.queryparams

    #23098

    Carolina
    Member

    Thanks Christian,

    I can use your suggested one, however my query parameters are dynamically generates.

    For example in my query parameters ‘trip’ and ‘origin1’ may or may not come, in that case how could I decides where I have to add <query-param name=”trip”> tag or not?

    that is the reason I have constructed query parameters and added into one of the bean variable “vacationsUrlParams” like below

    #{urlHandlerBean.vacationsUrlParams}

    Please give me hints how I can either avoid encode for the query parameter or dynamically I can generate the query parameters?

    Thanks,

    Vishwa

    #23099

    Query parameters are optional by their nature. So if you add a <query-param name="trip"> to your mapping, the mapping will match even if there is no trip parameter. In this case the bean property will be set to null.

    So you can simply add all the query parameters that MAY occur to the mapping. This has many advantages to your current approach. Especially you don’t have to parse the query string by yourself. :)

    #23100

    Carolina
    Member

    To avoid setting null values in browser URL, I am removing null parameters in query parameters.

    I am deciding before it self where the values are there, then only I have to set in query parameter or else I do not want those parameters which has to show as null.

    Before pretty faces URL re writing I could use my API that creates parameter on the basis of value null or not.

    Please give me some idea of work around to achieve this.

    #23101

    If the bean value bound to a query parameter in you config is null, the query parameter won’t be added to the URL.

    Have a look at the details here:

    http://ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.queryparams

    #23102

    Carolina
    Member

    Thanks Christian,

    I will test by setting null value for some parameters.

    #23103

    Carolina
    Member

    Hi Christian,

    Can I get any sample examples on setting parameter as array?

    because in my case I can get number of origins (dynamically) for examples

    origin1, origin2….

    and it should show in URL like

    /vacation-packages/search?origin1=BLR&origin2=LON&origin3=SIG

    #23104

    AFAIK arrays should work out of the box:

    <url-mapping id="flightPlusHotel">
    ...
    <query-param name="origin"> #{someBean.origin} </query-param>
    ...
    </url-mapping>

    With:

    public class SomeBean
    {
    private String[] origin = String[] { "BLR", "LON", "SIG" };
    }

    But this would render to:

    /vacation-packages/search?origin=BLR&origin=LON&origin=SIG

    If you really want origin1..n instead of multiple origin parameters, you could either add multiple <query-param> tags to your xml like this:

    <url-mapping id="flightPlusHotel">
    ...
    <query-param name="origin1"> #{someBean.origin1} </query-param>
    <query-param name="origin2"> #{someBean.origin2} </query-param>
    <query-param name="origin3"> #{someBean.origin3} </query-param>
    ...
    </url-mapping>

    Or you could simply do the complete query parameter handling yourself. Just use a mapping without any query parameters like this:

    <url-mapping id="flightPlusHotel">
    <pattern value="/vacation-packages/search" />
    <view-id value="/pages/package/flighthotel/flightPlusHotelResults.xhtml" />
    </url-mapping>

    And then use HttpServletRequest.getParameter*() methods to access the query parameters.

    #23105

    Carolina
    Member

    Thank you very much Christian :)

    #23106

    Carolina
    Member

    Christian ,

    I have used ‘/’ charters for date parameters and the browser is showing this charter as ‘%2F’.

    How can I use ‘/’ for dates (for ex: 11/10/2012)

    <url-mapping id=”flightPlusHotel”>

    <query-param name=”toDate”> #{someBean.toDate} </query-param>

    </url-mapping>

    #23107

    The / character is a reserved character in URL. Therefore it must be encoded. PrettyFaces behaves correct here. If you want the URL to look more pretty, you will have to use a character that isn’t reserved. Something like -.

    #23108

    See this page for more details:

    http://www.permadi.com/tutorial/urlEncoding/

    #23109

    Carolina
    Member

    Hi Christian,

    You are absolutely rite.The ‘/’ charter is reserved charter in URL. But I could not use ‘-‘ also for date format. Because as of I am using valid URL separators as ‘-‘ hyphen character. So could you give me any other suggestion to overcome this issue?

    #23110

    Sorry, but I don’t fully understand why you cannot use - as a separator in your date format. You could also choose any other character you like. You could also keep / although it is encoded and doesn’t look so pretty. But it should work.

Viewing 15 posts - 1 through 15 (of 20 total)

You must be logged in to reply to this topic.

Comments are closed.