At 05:22 AM 8/10/2004, you wrote:
Thanks, that goes some way...but not all the way though. A common situation where a dynamic page displays 0....n items with different identifiers. For example, an item list is fetched from database, and page contains delete buttons for items 23, 67, 101 and 128. I do not think you can use this approach to solve that problem. You would have to magically create getDeleteItem23, getDeleteItem67....methods in your class.


How about this, Janne:

public final class ButtonCommand {
  private ButtonCommand() {
  }

  public final static String getCommand(HttpServletRequest request) {
    Enumeration enum = request.getParameterNames();
    String parameterName = null;
    while(enum.hasMoreElements()) {
      parameterName = (String)enum.nextElement();
      if(parameterName.endsWith(".x")) {
        return parameterName.substring(0,parameterName.indexOf('.'));
      }
    }
    return parameterName;
  }
}

Now, you just dynamically make your name attribute of the <input type='image'> button, or the property attribute of your <html:image> button be whatever command you want on a dynamic or static basis. You can deal with the logic of what to do with your commands:

String command = ButtonCommand.getCommand(request);

anyway you see fit. I don't use buttons with indexed (0, 1, 2, ... , n) values, so I don't need to worry about that. That is easy to do, of course.

Michael

Cool, eh?

Michael



Reply via email to