Skip to Content
author's profile photo Former Member
Former Member

MVC-style application with command pattern


I am building a small MVC application using the (GoF-)command pattern. I tried to pretty much follow the way struts does it: a front controller maintains a map of specific action objects and decides which action to use based on some hint in the request. So far I was using the IDs of htmlb (button-)events to determine the appropriate action object - e.g. pressing a 'save'-button (i.e. a button having the ID-attribute set to the string 'save') would cause the controller to use his save-action. Data exchange is realized via data binding.

This all works fine provided there is only one button of a 'type' - in the sense of 'same ID', e.g. save-button, delete-button etc. which in turn trigger the according actions - per page.

Now I have a case where several buttons of the same type (i.e. same action required) are needed: a table with several entries each containing an itemnr. and a 'details'-button. Obviously I have to know which particular details-button was pressed, that is which item's details the user wants to see - in other words: I have to parameterize the the event/action.

Since with htmlb-style events there is no easy way to manipulate the request, the query string (i.e. form fields) is not an option. Currently I am using the value of the 'onClick' attribute wich is available in the htmlb-event to transfer the parameter (here the itemnr.). However this is most certainly not its intended usage 😉

As a sap/abap newbie I would be grateful if someone could comment on the following questions:

1. What do you think about the overall architecture, is this actually bsp-style?

2. How would you solve the parameter/'onClick'-issue in a cleaner way?


Sebastian Kamp

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Jun 05, 2004 at 08:34 PM


    I will not comment on your pattern aspects. Do what it takes to get the job done.

    As for the fact that you have several buttons that you for some reason have wired onto the same ID, there one of two ideas you can use to multiplex additional information.

    Let us assume that you use the ID to carry your command, such as PRINT, SAVE, etc. Then you can use the onClick string to contain any string that has a meaning to you. This string is transparently transported back and forth. Just write the sub-id information you require in there.

    Alternatively, render out one hidden field with an empty value that will be returned to the server. Set the onClientClick to fill this hiddenfield with the subId stuff you need. Pick it up in the controller again with a request->get_form_field.


    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.