JonTom,
A more standard way of doing this is to have a single FORM on the page and
have the Submit buttons be links to various JavaScript functions
(javascript:doSubmit(), javascript:doAddUser(), and so forth). Each of
these functions uses JavaScript to change the action of the Form and then
submit it:

document.forms[0].action = [put action here]
[some validation code]
if validation returns true {
  document.forms[0].submit()
}

That way, all of your data gets passed properly, and a separate action can
be taken for each button. Alternatively, you can use a single function and
pass it a parameter which you can use to conditionally change the form's
action.

You also mention the need to send the user to different pages (and perhaps
use the same action). To this end simply pass a hidden name value pair,
url=somejsp.jsp, or wherever you would like the user to end up.

In general, I would recommend against using mulitple input type=submit
buttons.

Eric M. Andersen
I/T Specialist
IBM Global Services
Tel: (781) 895-2637,   Fax : (781) 895-2843, t/line : 362-2637
Internet ID:  [EMAIL PROTECTED]
Lotus Notes ID: Eric M Andersen/Waltham/IBM


JonTom Kittredge <[EMAIL PROTECTED]>@JAVA.SUN.COM> on 11/29/99
05:24:58 PM

Please respond to JonTom Kittredge <[EMAIL PROTECTED]>

Sent by:  A mailing list about Java Server Pages specification and
      reference <[EMAIL PROTECTED]>


To:   [EMAIL PROTECTED]
cc:
Subject:  Flow-of-Control with Submit Buttons [Was Re: Which
      Architecture..?]



Craig, I find your Web Application Design Philosophy posts incredibly
useful.
They've been a big influence :-).

I've been building an app using a design similar to what you outline here,
specifically the part about using the request URI to dispatch to a given
page
"controller".

One issue that has caused me a lot of trouble, though, is that I often want
to be
able to have buttons on the same form send the user to different pages. Of
course, a
form can have only one target URL, so I am stuck there. Instead of using
<input
type="submit"> tags for my buttons, I could use links to different URLs,
but then my
servlet/controller would never see the values the user has entered into the
form,
which is important, since I want these buttons to go to "sub-pages" --
similar to
sub-dialogs in a conventional applications -- whose contents and behavior
will
depend on the values in the parent page.

I worked out a complex, hackish solution where, for each <input
type="submit"> tag,
I add a hidden field that adds the name of this button to the list of
submitButton
values, and another hidden field that maps the button names to the "real"
URI to
use. Then I use a special value for the forms target attribute to tell my
dispatching servlet to loop over the list of submitButton names, and see if
any of
them show up in the parameter list. If it does, I use the hidden field
parameter to
get the real URI. Wheww!

Any suggestions for approaches that may be more straightforward and easier
to
program?

Yours, JonTom

    JT Kittredge
    ITA Software
    Cambridge, Massachusetts

"Craig R. McClanahan" wrote:

> David's concerns are quite valid -- one of the implications of the
architecture
> I propose is that the servlet containing the business logic (essentially
the "C"
> in an MVC architecture) has to select processing logic (i.e. specific
Java
> classes) and the subsequent presentation logic (i.e. the URL of the JSP
page to
> be forwarded to), without hard coding the set of possible selections.
I'm going
> to briefly describe the approaches I use to deal with these issues, and a
couple
> of alternative approaches that seem to make sense as well.  (By the way,
the
> same issues apply in a JSP-Bean-EJB type architecture -- they are just
factored
> differently).
>
> SELECTING THE PROCESSING LOGIC
>
> The proposed architecture has a servlet receiving the input from every
form.  It
> can make a decision of where to go next based on the request URI that was
> received, the request parameters, and/or current state information from
the
> user's session. [...]

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to