restricting user choices in a form

J

Jean Lutrin

Hi everybody,

I have a Webapp where every request (even the welcome page) goes
through a controller servlet. Then some processing is done, mainly
creating beans that the jsp pages use. The "view" is really completely
decoupled from the logic (I am not the one doing the layout of this
site, btw... There's a "web designer" doing that. The guy is good, but
the problem is he's an artist, with not a single programming skill).

On one of the jsp page, there is a FORM that can later be POSTed by
the user when he clicks the Submit button (quite typical uh :)

This FORM is almost totally generated by the jsp, using 'for' loops.

Say my company is selling three kind of items : cubes, pyramids and spheres
(whatever) in different colors at various size and price.

What I want to do is allow the potential consumer to search through the items
currently available.

So, for example, they have a drop-down (option) list showing :

-Spheres (<option value="spheres">Spheres</option>)
-Cubes (<option value="cubes">Cubes</option>)
-Pyramids (<option value="pyramids">Pyramids</option>)
-Any (default selected choice) (<option value="any" selected>Any</option>)

and, for the colors, they have :

-Red
-Green
-Blue
-Yellow

also in a selectable drop-down list.

This is working fine, and all those "hmtl post options" are automatically
generated by the jsp.

If the user sets no restricting criteria and starts the search, I return a
page showing a thumbnail of every items in stock (well, design is more
complicated than that, because there are actually *many* items and they
definetely dont fit on one page... but our app takes care of this and
cache everything nicely etc.).

Now, what I want to do is this : if a user select "Pyramids", then only
the colors available for the pyramids item appears in the colors drop-down
list. If, say, the company sells only red and green pyramids, I want
the drop-down list to show only those two choices...

But these are not "fixed choices" : one week we may only have red and
green pyramids, but another week we may only have blue and yellow ones...

So I need the choices being restricted accordingly to our items in store.

This involves a partial client-side solution, like Javascript (I really don't
know much about Javascript, and I know this is not the right newsgroup :)

So how should I proceed ?

I don't want to add "kludge" to the nice design in place. This is nothing
urgent : it's just one those "wouldn't it be nice if..." things that
someone here proposed. Everything's working fine without that but it
would really be a little extra for everybody (maybe for my salary too :) if
you could point me to a clean solution to this problem.

Thanks in advance and sorry for the long post,

Jean
 
J

Jim

You might pass a matrix of flags to the jsp page indicating which
combinations
are valid. For example, if you had Color (red,blue,green) Form(
sphere,cube,dodecahedron,pyramid), and Size (xs,s,m,l,xl)
then you could represent each possible combination as a triple of
Color,From,Size values. In all there would be
3x4x5 = 60 possible triples for this example.

If your servlet built the appropriate vector of 60 booleans and passed it to
the jsp page, the jsp could figure out the valid combinations. (I'm assuming
a servlet is privy to the data and that jsp page is built by the servlet)

Hope this helps.

Jim Cant
 

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
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top