How to get Parameter with prettyfaces?

Splash Forums PrettyFaces Users How to get Parameter with prettyfaces?

This topic contains 7 replies, has 3 voices, and was last updated by  Christian Kaltepoth 11 years, 3 months ago.

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


    Hello All and Lincoln!

    My problem with URL , PrettyFaces URL is work well

    but i don’t know how to pass value from one JSF page to another JSF page with CommandButton through <f:setPropertyAction> , it mean when user click on button it pass value from button to other page and in prettyfaces i config get value from button pass to it follow:


    <url-mapping id="itemslist">
    <pattern value="/index/category/#{catItemsListController.subDetails.subcatName}" />


    {catItemsListController.subDetails.subcatName} <== it get name of category when user click on button,

    my trouble is: when user click on button it pass parameter from one page to other page, but when user bookmark other page example

    First user on http://localhost/index/ after click on button user go to http://localhost/index/category/prettyface

    and user bookmark this link : http://localhost/index/category/prettyface

    but when user close Browser and re-open it and go to bookmark page, content of it is empty, how can i get parameter with prettyfaces? i want pass parameter such as cateItemsListController.subCat



    my commandbutton code

    <p:commandButton  style="margin-top: 0px;margin-bottom: 5px;margin-left: 5px;background: #f2f5f7;border: #f2f5f7" value="#{subCat.subcatName}" action="#{catItemsListController.showDetailsSub(subCat)}" ajax="false">

    <f:setPropertyActionListener value="#{item}" target="#{subCatController.sub}" />


    it return to



    You should use a PrettyFaces action-method for this instead:

    <url-mapping id="itemslist">
    <pattern value="/index/category/#{catItemsListController.subDetails.subcatName}" />

    Please read the documentation here:



    Hi Lincoln!

    Thank you for support but my problem is , i must get parameter from other page. parameter is a instance of object , it is instace of items and in itemslist page i use h:dataTable display data and asign value is #{catItemsListController.subDetails.itemList} var=”item”

    i need help


    Right. I’m suggesting that you pass a value with which you can use to look up the item you need.

    Otherwise you would have to store the parameter in session in order to reference it on the next page.


    What Lincoln and I are talking about is something like this. Your second page will be mapped like Lincoln suggested:

    <url-mapping id="itemslist">
    <pattern value="/index/category/#{catItemsListController.nameOfCategory}" />

    This means the name of the category is embedded into the URL and will be injected into the field nameOfCategory of catItemsListController. After injection loadData() will be called. This method will typically load all required data from the database that is required by itemlist.xhtml to render correctly. This page is now completely independent from any other page of your application. If you enter an address like /index/category/test in the browser bar, the page will work as expected.

    In your first page you will now only have to create a “pretty link” to the second page. You have different options for this. One is to use pretty:link. Here is an example:

    <h:dataTable var="category" ....>


    <pretty:link mappingId="itemslist">
    <f:param value="#{}"/>
    Show Items


    This will render a standard HTML link containing the category name in the URL. If a user clicks on the link, the browser will send a GET request to this URL and the user will see your second page. This way you won’t need any JSF postback and so you don’t need to “transfer” a parameter from one page to another.

    I hope this helps.



    Thank you Lincohn and chkal, i do following your suggest but get error, i post my code in first page followed


    <ui:repeat value="#{catController.allCate}" var="category">
    <p:panel header="#{category.cateName}" style="font-size: 13px;border:0">


    <ui:repeat value="#{category.subCatList}" var="subCat" >

    <div id="css_vertical_menu">

    <p:commandButton style="margin-top: 0px;margin-bottom: 5px;margin-left: 5px;background: #f2f5f7;border: #f2f5f7" value="#{subCat.subcatName}" action="#{catItemsListController.showDetailsSub(subCat)}" ajax="false">

    <f:setPropertyActionListener value="#{item}" target="#{catItemsListController.sub}" />






    in my code first page as you an see, i use command button pass parameter to method in action of commandButton.

    and in my second page follow:


    <p:panel style="margin-top: 45px;font-size: 12px" header="Danh mục #{catItemsListController.subDetails.subcatName}">
    <!-- Form Register -->
    <h:form id="formlist">
    <p:growl id="displayMessage"/>
    <p:dataGrid var="item" value="#{catItemsListController.subDetails.itemList}" columns="3" rows="7" id="dataListItems">
    <p:panel style="text-align:center" >

    <h:panelGrid columns="1" style="width: 100%">

    <p:graphicImage value="/item/#{item.img}" />
    <h:outputLabel value="#{item.itemName}" style="font-size:small ;font-weight: bold" />


    <p:commandButton value="Chi tiết" style="font-size: x-small" action="#{catItemsListController.showItemSub(item)}">
    <f:setPropertyActionListener value="#{item}" target="#{catItemsListController.items}" />
    <h:outputLabel value=" "/>
    <p:commandButton value="Thêm vào giỏ" update="formlist:dataListItems,formlist:displayMessage,formlist:addtoCart,formlist:outstock" style="font-size: x-small" action="#{catItemsListController.addtoCart(item)}" rendered="#{item.instock gt 0}" id="addtoCart" />
    <h:outputText value="Hết hàng" rendered="${item.instock eq 0}" style="color: red; border: 1px;font-weight: bold" id="outstock"/>





    in this page it display details of Sub-Category but it just display sub-category name and display on datagrid is list of item, it have relational many to one with sub-category.

    i don’t know how to pass parameter with your suggest

    Thank you!


    Please take another look at my previous post. You should NOT pass any value from the first page to the second. If you do it this way, you lose any chance of creating working bookmarks for the second page.

    Please check my previous post on this again. It explains everything you need to know. It is important to understand that the two pages should be independent from each other. All information required to render the second page should be embedded in the URL. So you will have to add the category name (or its database id or something unique) to the URL like shown in my post and then use a page action to load the required data from the database. This way you won’t need to call any action method from the first page. You will only need to generate a simple link to the second page.

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

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

Comments are closed.