Date: Tue, 19 Mar 2024 01:55:16 +0000 (UTC) Message-ID: <1419459978.53997.1710813316834@cwiki-he-fi.apache.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_53996_986173877.1710813316834" ------=_Part_53996_986173877.1710813316834 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Assume that you have code not unlike:
<input type=3D'image' name=3D'update' src=3D'change.gif'> <input type=3D'image' name=3D'delete' src=3D'nuke.gif'>
or, in Struts' image tag:
<html:image property=3D'submit' src=3D'change.gif'/> <html:image property=3D'delete' src=3D'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 e= verything at a low cost and with great flexibility and freedom.
public class ImageTagUtil { public static String getName(HttpServletRequest request) { String command =3D null; String buttonValue =3D null; Enumeration enum =3D request.getParameterNames(); while(enum.hasMoreElements()) { buttonValue =3D (String)enum.nextElement(); if(buttonValue.endsWith(".x")) { command =3D buttonValue.substring(0,buttonValue.indexOf('.')); } } return command; } }
So, don't use buttons, but just mine the value of the [name].x request p= arameter.
Michael McGrady
(N.B.: This solution also works for non-image (submit) buttons by using = values like <input type=3D"submit" name=3D"add.x" value=3D"add"> in t= he submit button. Or, just use <input type=3D"submit" name=3D"button" va= lue=3D"add"> for a different solution for <input type=3D"submit"> = versus <input type=3D"image">)'''