Intercept request

Splash Forums PrettyFaces Users Intercept request

This topic contains 6 replies, has 2 voices, and was last updated by  mail@s-christensen.dk 2 years, 11 months ago.

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

    Hi

    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

    #24804

    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:

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

    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.

    Christian

    #24809

    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:

    http://mydomain.com/agro/da/search/0210

    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).

    #24810

    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” />
    <action>#{solrJsfFacade.findItemSearchBeans(searchtext)}</action>
    </url-mapping>

    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>
    </url-mapping>

    #24811

    … 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 🙂

    #24814

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

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

    Basically it allows to do something like this:

    <url-mapping id="base">
      <pattern value="/#{ store }/#{ language }" />
      <view-id value="/pages/unsecure/something.xhtml" />
      <action>#{someBean.doSomeCommonStuff}</action>
    </url-mapping>
    
    <url-mapping id="search" parentId="base">
      <pattern value="/search/#{ searchtext }" />
      <view-id value="/pages/unsecure/search/searchresult.xhtml" />
      <action>#{solrJsfFacade.findItemSearchBeans(searchtext)}</action>
    </url-mapping>
    

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

    #24815

    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)

You must be logged in to reply to this topic.

Comments are closed.