File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes How to handle request params and navigation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to handle request params and navigation" Watch "How to handle request params and navigation" New topic

How to handle request params and navigation

Gytis Jakutonis
Ranch Hand

Joined: Feb 02, 2004
Posts: 76

in plain web (jsp, php etc.) world I use simple technique to pass data between pages - url params. How to solve this issue with jsf?

Suppose we have page A with list of orders. Each order item is rendered as url to page B for single order management. Each url has param - order id. And that's all - simple.

Now I'm trying to handle the same logic with JSF. Seems like there is no simple solution for such a simple problem - pass id between pages. Possible solutions:

a.use request scope bean for page B and bind bean attribute orderID=#{param.orderId}. Main drawback - in some cases request bean is not enough (I need to store some page related data between requests). So if we do not want to pollute http session with page data like DataModel etc., we have to use session scoped bean for page B.

b.use session scoped bean for page B. In this case we can store data between requests (very useful then order editing spans over several pages). But now we have no ability to map bean attribute to request param.

b1.we either need to implement action listener and bind it in page A (getting order Id still is not straightforward for me)

b2.we can set orderId for our session bean in action handler in page A backing bean (getting bean from session is not straightforward too)

b3.we can parse request param in page B bean in method getOrder - compare current order id with requested one and reload order if needed. Main drawback - jsf strives to hide all that request parsing stuff, but seems like we are going back to old jsp style (just this time it is much harder to understand that is going on).

Another issue with case b is session bean cleanup. If we have many users and use this technique for many pages, we can get with a lot of session scoped beans and each bean may store quite large objects.

Any ideas? Which way is the true one from jsf perspective?
Andres Quinones
Ranch Hand

Joined: Oct 09, 2006
Posts: 57
1. Use the tag <f:param id="x" name="x" value="#{param.orderId}"/>. This tag should be between <h:commandLink><f:param/></h:commandLink>. So in the method in which you process the action of the commandLink you can get this param from the request in this way:

FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest request = ( HttpServletRequest )context.getExternalContext().getRequest();
String param = request.getRequestParameterMap().get(name);
Where name is the name you put in your f:param tag.

I hope this will solve your problem.
I agree. Here's the link:
subject: How to handle request params and navigation
It's not a secret anymore!