Ted,

Since I'm about to have to implement similar functionality to what you
describe, I dug out this message again, and have a few (OK, many :-) )
questions. See below.

----- Original Message -----
From: "Ted Husted" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 13, 2001 5:40 AM
Subject: Workflow Context


> Something that has come up now and again is the idea of a "workflow"
> context - more than a single request but less than a session.
>
> Towards that end, I've been experimenting with placing a Hashtable in
> the session where I can store objects between requests, and remove them
> when the mutli-request task is complete. I'm calling this a "Registry".
>
> My current test case is leaving an input form to go off and look up some
> foreign keys, and then have the keys filled in when you get back.
>
> To do this, I put an extra submit button next to the foreign keys. When
> the action sees one of these come in, it puts the ActionForm in the
> registry, and forwards to a search form for the key.
>
> String pickDonor = request.getParameter("pickDonor");
> if (pickDonor!=null) {
>     servlet.log("item.Access: Saving itemForm in Registry",2);
>     registry.put(formName,thisForm);
>     return mapping.findForward("pickDonor");
> }

What is 'formName' here? Is it the same as the 'name' attribute of the
<form-bean> in struts-config.xml?

> The data access Actions in the application register a form's key
> property when appropriate:
>
> // Remove or update donor key
> if (task.equals("delete"))
>   registry.remove(formKey);
> else
>   registry.setString(formKey,thisForm.getKey());
>
> This is stateless and happens whenever the key is accessed.

I guess I don't get where this code would live, and what would be going on
around it. Also, is 'formKey' the same as 'formName' in the previous
fragment? If the registry is a Hashtable, where does the setString() method
come from?

> Later, when they request an input form, the Action checks the registry:
>
> // -- Check registry; repopulate bean if form not finished
> if (registry.containsKey(formName)) {
>     servlet.log("item.Input: Restoring itemForm from Registry",2);
>     Form itemForm = (Form) registry.remove(formName);
>     try {
>         BeanUtils.populate(thisForm,itemForm.getMap());
>     }
>     // :TODO: Generate "unexpected error" message
>     catch (IllegalAccessException iae) {;}
>     catch (InvocationTargetException ite) {;}
>     thisForm.resetKeys(mapping,request);
> }

By "when they request an input form", do you mean when an Action's perform()
method needs to use the form that would normally come in through the 'form'
parameter?

You added an ActionForm to the registry in the first fragment, but you seem
to be obtaining a Form from it here, which also has a getMap() method. Does
Form extend ActionForm to support the registry functionality, and if so how?

> You will note that the final trick is a "resetKeys()" method on the
> ActionForm, which sets any foreign keys it is watching from the
> registry, or to a default value is there is no registry key.

I guess I don't understand "sets any foreign keys it is watching". Is this
where the new values from the lookup page get added in to the original page?

> The registry is being setup when they login. If I keep this structure, I
> could also keep the loginBean there so that my application just has the
> one session object to manage.
>
> I'll be testing and refining this approach more today, and just wondered
> if anyone else is working in this area.

One other question: how are you "remembering" how to get back to the page
you started on? Or is that not an issue because it's always the same page,
invoked the same way?

Thanks!

--
Martin Cooper


>
> -- Ted Husted, Husted dot Com, Fairport NY USA.
> -- Custom Software ~ Technical Services.
> -- Tel 716 737-3463.
> -- http://www.husted.com/about/struts/


Reply via email to