Passing URL parameters using Java ADF

Off late i have been asked this question a lot as to how to pass URL parameters in a Java ADF web application similar to ArcIMS HTML Viewer.

For example : You would like to open the web app and zoom to a given envelope

In terms of URL : http://www.myserver.com/myapp/mapviewer.jsf?action=zoom&box=100.56,65.87,-90.50,68.44

Other use cases might be :

  • Turning on/off layers
  • Adding resources dynamically
  • Passing an authentication token
  • Perform a query and show results on the graphic layer

Probably the easiest way of doing this is by tapping into the lifecycle of the web application using the Interface WebContextInitialize.

This can be done is three easy steps :

  1. Implement the Java class
  2. Register this class as managed bean in faces-config.xml
  3. Add this managed bean as an custom attribute to the WebContext in faces-config.xml

Step 1 : Here is the basic skeletal code for the Java class

import javax.faces.context.FacesContext;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebContextInitialize;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
import com.esri.adf.web.util.WebUtil;

public class MyParamsHandler implements WebContextInitialize {
public void init(WebContext webContext) {
java.util.Map params = null;
params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
//alternative way of getting the context or request parameters
//params = WebUtil.getExternalContext().getRequestParameterMap();
if (params != null && params.get("action") != null) {

//parse out the string you are looking for and implement your business logic here
String action = params.get("action").toString();

//House keeping
WebMap webMap = webContext.getWebMap();
WebExtent currExtent = webMap.getCurrentExtent();

if ("zoomin".equalsIgnoreCase(action)) {
currExtent.expand(0.5);
webMap.setCurrentExtent(currExtent);
} else if ("zoomout".equalsIgnoreCase(action)) {
currExtent.expand(1.5);
webMap.setCurrentExtent(currExtent);
}
webContext.refresh();
} //end of if
}//end of method
} //end of class

Step 2 : Register the class as Managed bean in face-config.xml file:

<managed-bean>
<managed-bean-name>myParamsHandler</managed-bean-name>
<managed-bean-class>com.esri.sample.MyParamsHandler</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
</managed-bean>

Step 3 : Add the managed bean as a custom attribute to the WebContext managed bean in faces-config.xml

<map-entry>
<key>myParamsHandler</key>
<value>#{myParamsHandler}</value>
</map-entry>
Advertisements

2 Responses to “Passing URL parameters using Java ADF”

  1. khalil Says:

    may my replay be late but I thing there is easier way to pass request parameters to your beans:

    setManagedProperty in the ManagedBean tag in faces-config.xml ::

    MBean_name
    view.beans.Mine
    request

    myParam
    java.lang.Integer
    #{param[‘param1’]}

    in Mine Bean there should be an attribute with myParam name and with setters and getters..

    in the URL :
    http://any:any/web-application/any_page.jsp?param1=2

    so in the setMyParam()
    the value 2 will be set

  2. Smithf741 Says:

    There is visibly a bundle to realize about this. I assume you made certain nice points in features also. bdcgcfbckkkabbbb


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: