Re: ADF, PrettyFaces and a persistent query param

Splash Forums PrettyFaces Users ADF, PrettyFaces and a persistent query param Re: ADF, PrettyFaces and a persistent query param

#21578

clemmonsm
Participant

Okay, I have done a bit of debugging and below is what I have found. It’s a lot of information, so hopefully I can make it simple.

Here is the rewrite match i am using for testing. It excludes images, css, js and some random ADF html and path resources:

<rewrite match="^(?:(?!.gif|.jpg|.jpeg|.png|.cur|.css|.js|.html|/afr/|#).)*$r?n?" processor="siteUtils.PrettyFacesAdfProcessor" redirect="301" /> <!-- do not match strings with these char strings -->

I am using a bare-bones custom processor code for this walkthrough with breaks on the return statements.

public class PrettyFacesAdfProcessor implements Processor {

public String processInbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rewrite, final String url) {
return url;
}

public String processOutbound(final HttpServletRequest request, final HttpServletResponse response, final RewriteRule rewrite, final String url) {
return url;
}
}

My test app includes two simple pages, each with a global header that includes two pretty:links.

Here is the life-cycle I see when debugging the custom processor:

@ processInbound() is called on the URL “/”. No “_adf.ctrl-state” param exists at this point.

@ processOutbound() is called twice on the URL ” “

@ processInbound() is called once on the URL “/?…” where “…” are ADF params, but not “_adf.ctrl-state”.

@ processOutbound() is called twice on the URL “/?…”. This is the first time the URL has the param “_adf.ctrl-state”

@ processInbound() is called once on the URL “/?…”

@ processOutbound() is called twice on the URL “/?…”. This is the first time the request object contains the param “_adf.ctrl-state”

@ processOutbound() is called twice on the URL “/”.

@ processOutbound() is called twice for each pretty:link that is placed on the page. Each time, the current ADF “_adf.ctrl-state” param value is available in the request object.

@ When a pretty:link is selected: processInbound() is called twice for the selected link.

@@ On the first call, the request object is empty – the previous “_adf.ctrl-state” value is gone. ADF sees this as a redirect from outside the framework.

@@ As a result, on the second call, ADF generates three params that are now tacked on to the end of the URL. The “_adf.ctrl-state” object has not yet been regenerated.

@ Next, processOutbound is called a number of times in the following order:

@@ Six times for the url-mapping that is being loaded. At this point, ADF has reinitialized the “_adf.ctrl-state” param and added it to the URL. The value is in the request object.

@@ Four times, twice for each of the two pretty:links found the page header

In your post, you say I “need to capture the original value of the parameter [in the processInbound method], to be saved into the request later until you need it when doing the processOutbound() method.”

From what I can see, I only have access to the param in the outbound method.

One fix I tried was to capture the value in processInbound() and save it to session, but access to FacesContext is not available at that time of the lifecycle.

The next thing I tried, was adding the param to the end of each pretty:link in the processOutbound() method. This allows me to persist the param across pages, but of course, I lose some prettiness because the query param is attached to the end of each pretty:link on the page.

In the event that the above is a bit too confusing, I would be happy to record a debugging session and share it online.