read parameter from backing bean

Read query string from backing bean  from  Hobione blog

http://myhost/mybean?inputId=1111

FacesContext context = FacesContext.getCurrentInstance();

  1. Map<String, String> params = context.getExternalContext().getRequestParameterMap();
  2. String ID = params.get(“inputId”);

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

Now ID should have the value 1111

For ADF in faces-config.xml:

<managed-bean>

<description>Backing bean for tree example. </description>

<managed-bean-name>tree</managed-bean-name>

<managed-bean-class>gov.faa.amc.nas.epf.TreeBean</managed-bean-class>

<managed-bean-scope>request</managed-bean-scope>

<managed-property>

<property-name>packageId</property-name>

<value>#{param.packageId}</value> <!–JSF injects query string value from request parameter –>

</managed-property>

</managed-bean>

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

view plain
copy to clipboard
print
?

private String packageId;

private String packageId;

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

view plain
copy to clipboard
print
?

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

refer to :

http://hobione.wordpress.com/tag/query-string/

Advertisements