Dashboard > WebWork 1 > WebWork CookBook > Multiple Graphical Submit Buttons
  WebWork 1 Log In View a printable version of the current page.  
  Multiple Graphical Submit Buttons
Added by Kirk Rasmussen, last edited by Hani Suleiman on Apr 25, 2004  (view change)
Labels: 
(None)

I was wondering if someone has tried using multiple graphical submit buttons on a single form?

For example let's say I have the following:

<form>
<input type="image" src="/img/sign_on.gif" name="doSignIn" value="Sign In">
<input type="image" src="/img/update.gif" name="doUpdate" value="Update Settings">
</form>

If I had regular submit buttons (i.e. type="submit"), the dispatcher would call "setDoSignIn()" and "setDoUpdate()) because the parameter name would simply be "doSignIn" and "doUpdate" respectively.

But in the case of graphical submit buttons the parameters sent from the browser become "doSignIn.x" and "doSignIn.y" and "doUpdate.x" and "doUpdate.y". Other than making my action ServletRequestAware and using the servlet request directly to look at the parameter is there a best practices for dealing with this issue?

The HTML 4 <button> tag won't work in our situation either. NS 4.7 doesn't support it.

ANSWER:

The cleanest way to do this is something like the following:

public void doValidation()
{
  ActionContext context = ActionContext.getContext();
  Map parameters = context.getParameters();
  for (Iterator iter = parameters.keySet().iterator(); iter.hasNext(); )
  {
    String key = (String) iter.next();
    if (doSignIn == null && key.indexOf( "doSignIn" ) >= 0)
    {
      setDoSignIn( "true" );
    } 
    else if (doUpdate == null && key.indexOf( "doUpdate" ) >=0)
    {
      setDoUpdate( "true" );
    }
  }
}

This is the cleanest solution I came up with without resorting to JavaScript.

public void doValidation()
{
  ActionContext context = ActionContext.getContext();
  Map parameters = context.getParameters();
  for (Iterator iter = parameters.keySet().iterator(); iter.hasNext(); )
  {
    String key = (String) iter.next();
    if (doSignIn == null && key.indexOf( "doSignIn" ) >= 0)
    {
      setDoSignIn( "true" );
    } 
    else if (doUpdate == null && key.indexOf( "doUpdate" ) >=0)
    {
      setDoUpdate( "true" );
    }
  }
}
Posted by Kirk Rasmussen at Feb 05, 2003 17:21 | Permalink

what works for me is to add a name="button" to the image submit tag .. webwork correctly populates the value in the action class.

Posted by Anonymous at Sep 03, 2004 07:54 | Permalink

Kirk,

Where is doValidation being called from? To what object does it belong?

  • Jason
Posted by Jason A. Lunn at Oct 15, 2004 00:44 | Permalink
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request - Contact Administrators