Intercept request

Splash Forums PrettyFaces Users Intercept request

This topic contains 6 replies, has 2 voices, and was last updated by 8 years, 4 months ago.

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


    Is it possible to define a method which will be called everytime a mapping is used?

    My problem is that I have a object used for storing some information about the user – and currently I’m initializing this object when certain url’s are called – however sometimes the user might have a direct link and as a result they will not call my initialization mapping during navigation = user object is empty 🙁

    After searching around I see the using ReWrite I might be able to do this – but is it possible in PrettyFaces as well?

    Thanks in advance

    Best regards

    Søren Christensen


    Hey Søren,

    yeah, sure. That’s what page actions are all about. You specify a method and each time a client hits the mapping URL this action will be invoked. Have a look at this chapter of the documentation for details:

    However, it sounds like your use case can perhaps even be implemented without PrettyFaces at all (if I understand it correctly). If you are using CDI or Spring, you could create a producer or a factory-bean for the object and simply inject the object into your bean. This way the object will be created whenever it is required.



    Hi Christian

    Thanks for your reply. I’m using page actions already – but what I need is to have a method called even before the page action, and called on all mappings.

    My problem is that I have an url like this:

    This will call a page action to perform a search in my items for partnumbers having 0210 – so far so good. The only problem is that to perform this i need to know which context the user is running in – the /agro/da/ part of the url. But I don’t want to implement logic for interpreting this in all page actions – so I would like to have a method called before each page action, and this will be responsible for interpreting the context part of the url, and updating my user object with the knowledge needed for performing the search (or whatever the user has choosen to do).


    I could of cause add them as extra parameters – so if goes from:

    <url-mapping id=”search”>
    <pattern value=”/#{ store }/#{ language }/search/#{ searchtext }” />
    <view-id value=”/pages/unsecure/search/searchresult.xhtml” />

    To this:

    <url-mapping id=”search”>
    <pattern value=”/#{ store }/#{ language }/search/#{ searchtext }” />
    <view-id value=”/pages/unsecure/search/searchresult.xhtml” />
    <action>#{solrJsfFacade.findItemSearchBeans(store, language, searchtext)}</action>


    … it was just to avoid having to send these parameters along all the time, and avoid relying on the programmer to remember to set the parameters on the user object before performing any work 🙂


    Did you think about using mapping inheritance for this? Have a look at this part of the documentation:

    Basically it allows to do something like this:

    <url-mapping id="base">
      <pattern value="/#{ store }/#{ language }" />
      <view-id value="/pages/unsecure/something.xhtml" />
    <url-mapping id="search" parentId="base">
      <pattern value="/search/#{ searchtext }" />
      <view-id value="/pages/unsecure/search/searchresult.xhtml" />

    This way all the common stuff is done in the “base” mapping and all sub-pages inherit from this mapping.


    I knew there was a smart way to do this 🙂 I think this solves my problem 100%.

    Thanks for your help.

    Søren Christensen

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

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

Comments are closed.