You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Mattos, John" <jm...@Indemand.com> on 2002/02/13 17:08:28 UTC

RE: HTML / Struts Help - Summary

Jay

Thanks a lot. To summarize, here is my HTML

<!-- HTML Snippet-->
<html:submit property="btnProcess">
	<bean:message key="button.processSuspends" />
</html:submit>
<html:submit property="btnViewOrg">
	<bean:message key="button.viewOrg" />
</html:submit>
<html:submit property="btnViewProd">
	<bean:message key="button.viewProd" />
</html:submit>
<!--  End of snippet-->

and in my Action Class, I have the following
   String button_pressed = null;
   Enumeration e = request.getParameterNames();
   while (e.hasMoreElements()) {
   String param = (String) e.nextElement();
   if (param.startsWith("btn")) {
        button_pressed = param;
       break;
   }
}

Works like a champ

Thanks a lot.

the other thing I found out I could have done, was, based on the SAME HTML
SNIPPET I could have a property on the ActionFormClass called BtnProcess
(with getter and setter) and I could get its value as follows 

// in the Action Form.perform()
ViewProcessSuspendsForm myForm=(ViewProcessSuspendsForm)form;
System.out.println("From the Action Form, getProcess(), the value is
"+myForm.getBtnProcess());

// Note, the value I get from this corresponds to <bean:message
key="button.processSuspends" /> from the HTML, which is the label on the
button loaded from the resource file. It happens to be "Process Suspends". I
like the first solution better.

Anyway, thanks for all the responses and help.

John

John Mattos
Sr. Developer and Architect
iNDEMAND
345 Hudson St. 16th Floor
New York, New York
10014
-----Original Message-----
From: Jay sissom [mailto:jsissom@toybox.uits.indiana.edu]
Sent: Wednesday, February 13, 2002 10:25 AM
To: Struts Users Mailing List
Subject: Re: HTML / Struts Help


You would do it the way you'd do it an any web application.

Here's how I do it:  All my button field names start with "btn".  I would 
name these buttons btnProcess, btnViewByOrg and btnViewByProcess (or 
something similar).

In my perform method, I'd put code like this:

   String button_pressed = null;
   Enumeration e = request.getParameterNames();
   while ( e.hasMoreElements() ) {
      String param = (String)e.nextElement();
      if ( param.startsWith("btn") ) {
         button_pressed = param;
         break;
      }
   }

At this point, button_pressed tells you the name of the button that was 
pressed.  I have a utility class that has this code in it and I use it 
everywhere.

Jay

On Wed, 13 Feb 2002, Mattos, John wrote:

> Hi.
> 
> I have a form that can be submitted by three different buttons, for
example
> the buttons read
> 
> (Button Labels)
> Process
> View by Org
> View by Product
> 
> What I want to do is in the Action Class handling the submission, find out
> which button was pressed, and act accordingly, whether it's an
actionForward
> (in the case of the "view" options) or kicking off another process (as
will
> be done by the "process" button)
> 
> So, how can I figure out what button was pressed in that Action class? Is
> there a way to do that?
> 
> John Mattos
> Sr. Developer and Architect
> iNDEMAND
> 345 Hudson St. 16th Floor
> New York, New York
> 10014
> 
> 
> 
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>