Date: 2004-08-11T18:09:08
   Editor: MichaelMcGrady <[EMAIL PROTECTED]>
   Wiki: Apache Struts Wiki
   Page: StrutsCatalogMultipleImageTagsSimplified
   URL: http://wiki.apache.org/struts/StrutsCatalogMultipleImageTagsSimplified

   no comment

New Page:

StrutsCatalog: '''This is an efficient way to end forever that pesky and recurrent 
problem of how to use multiple image buttons in your forms.'''


'''Assume that you have code not unlike:'''

{{{
<input type='image' name='update' src='change.gif'>
<input type='image' name='delete' src='nuke.gif'>
}}}

'''or, in Struts' image tag:'''

{{{
<html:image property='submit' src='change.gif'/>
<html:image property='delete' src='nuke.gif'/>
}}}

'''Now, how do we know which image has been clicked?  The answer has been complicated 
and costly in the past.  Here is a simple way to achieve everything at a low cost and 
with great flexibility and freedom.'''

{{{
    String button = null;
    Enumeration enum = request.getParameterNames();
    String parameterName = null;
    while(enum.hasMoreElements()) {
      parameterName = (String)enum.nextElement();
      if(parameterName.endsWith(".x")) {
        button = parameterName.substring(0,parameterName.indexOf('.'));
      }
    }
}}}

'''There you go. Toss out the !LookupDispatchActions, the !ButtonCommands, etc.  This 
is a done deal.  You can clearly seek other ways to ensure a bit more safety.  For 
example, the code works equally as well with "submit.button" as it does with "submit". 
 Elegant, no, eh?

Michael !McGrady
Cap't of the Eh Team'''


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to