Struts - Creating a generic lookup page - help

R

Rydell

I'm using Struts 1.2, and I'm having difficulty creating a lookup page
that can be accessed from a series of other pages.

For example, given a typical employee tracking system, when entering a
new employee's information, I will be entering their name, phone, and
supervisor. Since the list of potential supervisors is very long, I
don't want to use a drop list, I want to redirect to a supervisor
lookup page. After searching for the correct supervisor, I want to
select the supervisor, and return back to the initial new employee
entry page.

Naturally, if I have entered in the new employee's name and phone
number, I expect that it will be there upon return from the supervisor
lookup page. As the user, I will miffed if that information is no
longer there. But that is exactly what happened the first time I wrote
the page.

I solved this the only way I knew how, and that is to share a single
(session-scoped) form between the new employee page, and the supervisor
lookup page. Works just fine. Except for the fact that I have
hopelessly coupled my supervisor lookup jsp to my new employee jsp.

Which is fine until I discover the 4 other pages that have the same
need for a supervisor lookup feature. Now I'm either copying the
lookup page and action classes, or I'm sharing one massive form between
many pages.

So as a struts rook, I am stumped. I'm sure someone else has had a
problem like this, but I can't find reference to one. Each time I try
to "genericize" the supervisor lookup page, I get stumped by the fact
that the lookup page jsp has references to the specific form class, and
a need to know what page called the lookup page, so I can properly
return to it.

Granted it is a lame solution, which is why I'm having the problem. So
perhaps there is an obvious way to make it work? Or perhaps my
approach to saving state in the calling page (the new employee page) by
using a shared form could use some rethinking.

All comments appreciated -

Rydell
 
W

Wendy Smoak

Rydell said:
I'm using Struts 1.2, and I'm having difficulty creating a lookup page
that can be accessed from a series of other pages.

This is one situation in which chaining Actions is useful. It's generally
frowned upon, but there are times, like this one, when it makes life MUCH
easier.

I also use the same lookup for multiple forms (it happens to be an employee
lookup, too.) Here's some of struts-config.xml:

<action path="/editContact"
type="edu.example.EditContactAction"
name="contactForm"
scope="session"
input="contact.report.page"
validate="true"
parameter="userAction">
<forward name="resolution" path="/resolveName.do" />
.... </action>

<action path="/resolveName"
type="edu.example.ResolveNameAction"
scope="request" >
<forward name="success" path="resolution.page" />
<forward name="failure" path="resolution.failure" />
</action>

When they click on the "add person" button, the EditContactAction will set
some request attributes (the important one being 'returnTo') and forward
them to ResolveNameAction. It does the lookup puts a List in request scope,
and forwards to the resolution page. The form on the resolution page is NOT
a Struts form. It's plain old HTML, and it posts back to the *original*
Action (EditContactAction in this case):
<form action="<c:eek:ut value="${returnTo}"/>" method="POST">

There are half a dozen Actions that share the same resolution/lookup page.
There is no facility in Struts to learn "where did I come from" so you have
to store that bit of info in order to get the user back where they belong.
All the Struts forms are in session scope so nothing gets lost as they move
around.

Hopefully that was enough to get you started if you decide to take this
approach.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top