Hi,

>*       Some of our forms have multiple submit buttons for a single form
>(ex. Save, Delete, Find, Add, Remove, etc). My dilemma here is if
>I have one
>action per form, my actions are not as specific as I would like them to be.
>(Having FindCustomer and SaveCustomer handled by the same action).  What I
>have tried in the prototype is  giving the buttons the same NAME (Button)
>and assigning different VALUES (Find,Save,Delete).  My controller servlet
>then retrieves the Button value into a prefix (prefix =
>request.getParameter("Button") ) and adds the prefix to the URL. So
>"/Customer.do" becomes a "SaveCustomer" or "FindCustomer" action. Then use
>this action in the Hashtable/Property List to get the specific
>action class.
>
>        Am I way off base here? Is there a more straightforward approach?
>Are there some drawbacks I'm missing?

If it works..whats wrong with it? Seems logical to me. My only worry in your
case is what about the forms that don't have multiple buttons? Does the
servlet try to handle multiple buttons..or do you have some way of telling
the servlet there is only one button, and ignore the code that gets the
names from others?

Other than that..the only other way I could see doing it is using JavaScript
to "change" the action name:

<input type="submit" onclick="changeButton('Save')" value="Save">
<input type="submit" onclick="changeButton('Delete')" value="Delete">


The javascript might be like:

function changeButton(str)
{
  if( str.length > 0 )
  {
    document.forms[0].action = str + "User";
  }
}

I don't recall if that's it exactly..but we do something like this in a page
or two that contain two or more buttons for one form. It changes the
"action" of the form before submitting it, so that the right action can be
called. The only downside ofcourse is you need to make sure you force
JavaScript otherwise it wont work.

Its a matter of opinion. IF what your doing works, leave it..you can avoid
forcing javascript use that way.


>
>*       Also, we have multi-page forms using a "Next" button.  However, we
>also provide tabs along the top to give the user the flexibility to go to
>the pages in any order. My problem here is keeping the complexity down for
>determining the Next page in the Action class.  I've batted around a few
>different solutions which all seem to have their own drawbacks.  The one I
>like best today also uses the value of "Button":  Have the Button
>value take
>the form of action.nextpageKey  (Next.Order, Next.DestinationAddress, etc)
>where "Next" is the prefix to apply to the URL as described above, and
>"Order" is the key into my HashTable/PropertyList to find the next page in
>the "happy" scenario.
>        What I don't like about this is that I'm relying too heavily on the
>value of Button for multiple purposes.

Out of curiosity, why is it a big deal to link directly to the page? If it
simply jumps to that JSP page, your ok. The main thing to do is use a
session JavaBean to store all the forms data so that if they bounce around a
page, it redisplays what they have typed in. Ofcourse..they will have to
SUBMIT the form on each page before it "stays" in the bean. An alternative
is to have any one of those links to various pages ALL submit the form,
passing in a hidden value or something that tells where to forward to. The
approach Daniel, Craig and I have been talking about uses the XML file to
allow you to not hard-code forwarding urls to JSP pages. Maybe you can
"group" actions together, and have all links (next, forward, this page, that
page, etc) submit as a Group, passing in the appropriate information for the
servlet to figure out the action and the forwarding URL. Just a thought.
Another idea..maybe just have your servlet look for a specific request
parameter. For example, you may have a few links like so:

<a href="javascript: submitForm(0, 'page1.jsp')">Page 1</a>
<a href="javascript: submitForm(0, 'page2.jsp')">Page 2</a>

Ofcourse, your stuck using javascript again, but the idea is that the
javascript routine is passed in the form (if you have more than one form on
a page..otherwise ignore this and use the document.forms[0] to grab the only
form on the page) and the page to go to. The function would then "submit"
the form but first change the action to the next page. Maybe something like:

function submitForm(frm, pge)
{
  if( pge.length > 0 )
  {
    document.form[frm].action = "Submit.do?forward=" + pge;
    document.form[fmr].submit();
  }
}

Again..my javascript is a bit rusty..trying to break away from doing that
stuff and more java programming. But I believe it is something like that.
That would set the action to something.do (whatever you use) and pass in the
request value of forward = pge where pge is the passed in string. This way,
your controller servlet would still strip the action, call the action class
and the action class would get the JavaBean (or create it if it was the
first time submitting), fill in the request parameters for that form into
the bean, then look for the 'forward' parameter. If it existed, it would
then forward to THAT page, otherwise, it would forward to the NEXT page in
line.

Well..hopefully it makes some sense. ;) Not sure if what I am proposing for
you would work..but this is at least the first thing I would try. Trial and
error..its a grand thing.

Hope that helps.

Take care.

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to