how to pass query parameter and not show them in URI

Splash Forums PrettyFaces Users how to pass query parameter and not show them in URI

This topic contains 2 replies, has 2 voices, and was last updated by  xuzhike 5 years, 1 month ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18304

    xuzhike
    Participant

    Dear PrettyFaces team,

    would you please help to check my following question:

    I want to click a <h:link with query parameter, but hope the parameter not shown in URL, here is my setting:

    1: link xhtml page with two parameters: target and type

    <h:link outcome=”/pages/about/about.xhtml” value=”Company Info”>

    <f:param name=”target” value=”gsjj” />

    <f:param name=”type” value=”s” />

    </h:link>

    <h:link outcome=”/pages/about/about.xhtml?target=zczc&type=c”>Big Event</h:link>

    2: pretty-config.xml

    <url-mapping id=”companyInfoV”>

    <pattern value=”/v/compInfo/></pattern>

    <query-param name=”target”> #{companyInfoView.target} </query-param>

    <query-param name=”type”> #{companyInfoView.type} </query-param>

    <action>#{companyInfoView.loadPageData}</action>

    <view-id value=”/pages/about/about.xhtml”></view-id>

    </url-mapping>

    // #{companyInfoView.loadPageData} will get data from DB basing on query parameters

    // debug :

    public void loadPageData(){

    System.out.println(“target=”+target+”; type=”+type);

    3: when I click any button, got the following URI and action executed with correct value of query parameters.

    http://localhost:8080/huashi/v/compInfo?target=gsjj&type=s

    But this is not my expected result, I hope when I click button, the following URI return:

    http://localhost:8080/huashi/v/compInfo/gsjj/s

    then I changed pretty-config.xml as following (change <pattern />)

    1)

    <url-mapping id=”companyInfoV”>

    <pattern value=”/v/compInfo/#{companyInfoView.target}/#{companyInfoView.type}”></pattern>

    <query-param name=”target”> #{companyInfoView.target} </query-param>

    <query-param name=”type”> #{companyInfoView.type} </query-param>

    <action>#{companyInfoView.loadPageData}</action>

    <view-id value=”/pages/about/about.xhtml”></view-id>

    </url-mapping>

    this time, URL not changed, at the same time, the action NOT executed:

    http://localhost:8080/huashi/pages/about/about.xhtml?target=gsjj&type=s

    debug info: (no any info about query-parameter) too strange

    Processing new Request!

    before – RESTORE_VIEW 1

    after – RESTORE_VIEW 1

    before – RENDER_RESPONSE 6

    after – RENDER_RESPONSE 6

    Done with Request!

    2) remove {companyInfoView

    <url-mapping id=”companyInfoV”>

    <pattern value=”/v/compInfo/#{target}/#{type}”></pattern>

    <query-param name=”target”> #{companyInfoView.target} </query-param>

    <query-param name=”type”> #{companyInfoView.type} </query-param>

    <action>#{companyInfoView.loadPageData}</action>

    <view-id value=”/pages/about/about.xhtml”></view-id>

    </url-mapping>

    this time, when click button, got correct URL, action executed But still not got the query parameter value,

    http://localhost:8080/huashi/v/compInfo/gsjj/s

    debug info:

    Processing new Request!

    before – RESTORE_VIEW 1

    after – RESTORE_VIEW 1

    target=null; type=null

    would you please help?

    thx a lot

    #22431

    Simply removing the unnecessary query parameter statements from your configuration should do what you want… If you don’t need them, don’t use them :) If you still want bean injection, you can use the syntax I pasted below.

    <url-mapping id="companyInfoV">
    <pattern value="/v/compInfo/#{target : companyInfoView.target}/#{type : companyInfoView.type}"></pattern>
    <action>#{companyInfoView.loadPageData}</action>
    <view-id value="/pages/about/about.xhtml"></view-id>
    </url-mapping>

    #22432

    xuzhike
    Participant

    Thanks for your help, Lincoln. it works now.

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

You must be logged in to reply to this topic.

Comments are closed.