Hobione's Weblog

Living & Breathing in Web 2.0 Era

Read query string from backing bean – 2 ways

I needed to read a parameter from query string in JSF backing bean. http://atowus/epf?packageId=17169

Here how it works:

 FacesContext context = FacesContext.getCurrentInstance();
 Map<String, String> params = context.getExternalContext().getRequestParameterMap();
 String pID = params.get("packageId");

Now pID should have the value 17169


In faces-config.xml:
 <description>Backing bean for tree example. </description>
 <value>#{param.packageId}</value> <!--JSF injects query string value from request parameter -->

In TreeBean.java, I have a instance variable and getter and setter

private String packageId;

Caution: Bean scope has to be request otherwise you get a nasty error like this.

javax.faces.FacesException: Problem in renderResponse: Unable to create managed
bean tree. The following problems were found:
- The scope of the object referenced by expression #{param.packageId}, request, is shorter than the
referring managed beans (tree) scope of session note

June 4, 2008 - Posted by | Java Server Faces |

1 Comment »

  1. Great blog; your topics regarding Java EE (Seam, JPA, Hibernate, RichFaces) are very much in-line which our development efforts at my own place of work.

    Keep it up. Thanks.

    Comment by Chris | July 2, 2008 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: