Help using ParameterHandler

Hello,

In my application, I have clickable points in my flash charts that once clicked, they will open another IE window that will go to my application’s URL but will append extra parameters that will be used to generate a report.

For example, my URL is:

http://192.168.116.128:7001/dashboard

When I click one of the points in my chart, it will give:

http://192.168.116.128:7001/dashboard?k=45AF10E98312D8FE8032D6AF89A6AF9A&r=0&t=01/02/2008%2005:05:59

The three parameters here are:
A password key (k), a report index (r) and a timestamp (t).

In order to interpret these parameters I have the following code:

class MyParameterHandler implements ParameterHandler {
		public void handleParameters(Map parameters) {

			// Print out the parameters to standard output
			for (Iterator it = parameters.keySet().iterator(); it.hasNext();) {
				String key = (String) it.next();
				String value = ((String[]) parameters.get(key))[0]
;
				System.out.println("Key: " + key + ", value: " + value);

				if (key.equals("k")) {

					try {
						String decrypted = decrypt(value);

						if (decrypted.equals(LOOKUP_STRING)) {
							System.out.println("Ready to perform lookup.");
							lookupPermitted = true;
				      System.out.println("Lookup="+lookupPermitted);
						}
					} catch (Exception e) {
						// Do nothing
					}
				}

				if (key.equals("r")) {

					try {
						lookupReportIndex = Integer.parseInt(value);
					} catch (Exception e) {
						// Do nothing
					}
				}

				if (key.equals("t")) {

					try {
						SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
						Date d = sdf.parse(value);					
						lookupDate = value;

					} catch (Exception e) {
						// Do nothing
					}
				}

			}

		}
	}


What I’d like to do with this information, is allow the user to bypass the login screen and a report will be generated. The problem I am having is that the ParameterHandler seems to be handling the URL and detecting a lookup but then right after that it seems as though my application is initialized again but this time with the URL missing the parameters.

I have been able to detect this by creating a global variable called lookupPermitted. I set it to true when the lookup succeeds in the ParameterHandler. After the parameter handler code I have outputted this ‘lookupPermitted’ value and it has been reset to false (which is not done anywhere in the code, aside from the initial declaration).

If my window code is:

[code]

public MainWindow(MainApplication a) {

	// Get the application reference
	appRef = a;

	final VerticalLayout mainLayout = new VerticalLayout();
	setLayout(mainLayout);

	MyParameterHandler handler = new MyParameterHandler();
	this.addParameterHandler(handler);
	System.out.println("Lookup="+lookupPermitted);
 }

[/code]

The value of my lookupPermitted will detected as true in the handler, but false outside of it.

Here is the output from the log:

Key: k, value: 45AF10E98312D8FE8032D6AF89A6AF9A
Ready to perform lookup.
Lookup=true
Key: t, value: 01/02/2008 05:05:59
Key: r, value: 0
Lookup=false

Any ideas why?

I am experiencing this with 5.3.0 RC10 and 5.3.0 RC12 of the toolkit.

P.S. Sorry for the lengthy message.

Thanks,
Ajay

Hi everybody,

I was able to resolve my issue.

In case anybody has a similar type of issue this is what was happening.

My application class was doing the following operations:

  1. Create a window
  2. Set this newly created window as the main window

The problem was that all of my login/runtime code was in the constructor of the window class. By moving my login/runtime code outside of the constructor and calling another function from the application class, the issue was fixed.

In other words:

My application class now does the following operations:

  1. Create a window (the constructor is empty)
  2. Set this newly created window as the main window
  3. Call doMainWindow() which is a function that has all my login/runtime code.

Regards,
Ajay

Just in case it would be usefull for anyone else, add my implementation of similar pattern:

In my implementation (where url parameters are used to login with pre-provided username/password ) I created another empty window with the name “autologin”. So, external html form or user-href uses the following url syntax to go to the application and automatically login:

http://server.com/myapp/autolgin?user=xxx&password=yyy

The autologin window is just empty. It only contains a parameter handler, that performs authentication and then redirects (via Window.open) user to a main application window, which in case of unsuccessfulll authentication will be replaced by regular app login screen.

ajay, how have you made your flash charts?

For the flash charts, we actually have our own flash app, but to integrate it into the IT Mill Toolkit, I followed the instructions in:

http://dev.itmill.com/wiki/Articles/IntegratingCustomFlashWidget

The trick was to create a widget based off of a “Select” component which has most of the UI functionality we required for flash charting.