Share

JStateMachine

Tracker: Feature Requests

5 Multiple submit buttons in a one form for different events - ID: 703791
Last Update: Settings changed ( bobyrne )

The Request object should be able to determine the
event using forms like the following:

<FORM ACTION="State.Event.jsm">
<INPUT NAME="textData">

<INPUT TYPE="submit" NAME="event.Event1"
VALUE="Do
First Thing">
<INPUT TYPE="submit" NAME="event.Event2"
VALUE="Do
Second Thing">
<INPUT TYPE="image" NAME="event.Event3"
SRC="...">
</FORM>

The point being, that the VALUE of the submit button is
not the actual event name, since for display purposes,
we want to use a different value. So instead, the
event name is encoded in the parameter name. The
Request code would enumerate all the parameters to find
one that begins with "event.". Furthermore, image
buttons should work. For that to work, we just need to
remove the ".x" or ".y" from the end of the request
parameter name to get the event name.

Also, when using the .jsm notation, the request
parameters are ignored. It should first check if the
request parameters were submitted, and then fall back
on parsing the servletPath. That way in the form above,
if the user presses a button, that will specify the
event. But if the user just presses enter from the
text field, and the form is submitted with no event
parameters, the event is determined from the servletPath.

- Chris


Chris Felaco ( cfelaco ) - 2003-03-14 19:23

5

Closed

None

Brian O'Byrne

None

None

Public


Comments ( 5 )




Date: 2003-04-06 21:05
Sender: bobyrne

Logged In: YES
user_id=151201

Chirs,

First, my apologies for the long silence on this. Other commitments took
priority for the last few weeks.

A plan:
- Add a new optional parameter 'statemachineEventPrefix'.
- If statemachineEventPrefix is specified the Request will search for
parameters beginning with that prefix and guess the event name.
- If statemachineEventPrefix is not specified, or the event name cannot be

found by searching the parameter list for parameters beginning with the
prefix, the Request will fall back onto the scheme of checking the
statemachineEventName parameter then the URL (note the reversal from
the current order of checking the URL then the parameter)

I think this gives the HTML developer freedom to specify all the options
by
choosing the URL and parameters appropriately.

Code will be in CVS shortly.

Brian.



Date: 2003-03-18 15:59
Sender: cfelaco

Logged In: YES
user_id=29030


Well, I sometimes think the phrase "simple and unambiguous"
when applied to the web is an oxymoron. :-) But I applaud
your efforts.

Here's another thought. If you don't like the idea of
iterating over every request parameter, maybe the answer is
just another bit of indirection. Use a hidden parameter to
specify the names of the event parameters to check for.
This adds a bit more work for the HTML author, but less work
for the Request processor. Example:

<FORM>
<INPUT TYPE="HIDDEN" NAME="eventParameters"
VALUE="eventButton1:EventName1">
<INPUT TYPE="submit" NAME="eventButton1"
VALUE="Try This">

<INPUT TYPE="HIDDEN" NAME="eventParameters"
VALUE="eventButton2.x:EventName2">
<INPUT TYPE="IMAGE" NAME="eventButton2"
SRC="/images/foo.gif">
</FORM>

When this form is submitted,
request.getParameterValues("eventParameters") will return an
array {"eventButton1:EventName1",
"eventButton2.x:EventName2"}. We then parse the two parts
of each of the values - the first part is the request
parameter and the second part is the event name. Then if a
request parameter named "eventButton1" is found, we use the
event "EventName1". If not then it moves on and checks for
"eventButton2.x". This neatly solves the problem of IMAGE
buttons without adding special code to the request parser.
I wish I could think of a better way to specify the mapping
from request parameter name to event name, but that would
involve even more hidden fields in the form.

If you don't mind iterating over the parameter names, then
you can use a "magic" prefix, like in my original suggestion.

I agree that simple precendence rules must be defined. I'd
do it in this order:
1) check for "statemachineEventName" parameter
2) check for "eventParameters" and pick the the first
event which has a request parameter submitted
3) check the requestUri .jsm syntax

I really think the requestUri parsing should be a last
resort. It only seems useful to me with simple sites like
jstatemachine.org itself. It's really convenient for links,
but not so great for forms.

Of course all of this would be unnecessary if the original
HTML spec had a better way of doing submit buttons, but
complaining does me no good. :-(

- Chris



Date: 2003-03-17 23:23
Sender: bobyrne

Logged In: YES
user_id=151201

OK, I think I understand the requirement now. What you are looking for is
a
third way to specify the event name. Not as a parameter value or in the
URL but in a parameter name identified by a given prefix.

I'll look into it. My first concern as I think about it is that I don't
want there
to be any ambiguity about how the event name is retrieved. At the moment

if the URL ends with .jsm the URL will be used to find the event name,
otherwise the named parameters will be used. With another
scheme it becomes possible for there to be a statemachineEventName
parameter and an event.eventName parameter. Also you are suggesting
parsing the parameters first, before looking at the URL. This leaves the

possibility that all three event specification schemes could exist in the
same
request. Priority would have to be decided on a very simple and
unambiguous rule.

Please let me know if you have any thoughts on what that rule could be.



Date: 2003-03-17 20:24
Sender: cfelaco

Logged In: YES
user_id=29030


Using client-side scripting to override the button value is
not a solution since it requires client-side scripting just
to make the form work properly. I would use the <BUTTON>
tag, but IE 5.5 submits the value of the tag contents
instead of the value of the "value" attribute. The same
issue prevents me from using the <BUTTON> tag instead of
<INPUT TYPE="image">. So in short, there needs to be a
way
to select an event based on the presence of a request
parameter, and not just from the value.

Using different extensions for forms that use the parameters
and forms that don't is a good idea, but it doesn't allow
for the fall-back default event I was looking for. I
wanted to be able to handle the forms when the user doesn't
press any button at all. I suppose a hidden event field in
the form after the submit buttons might do the trick for
that, I'll have to experiment.



Date: 2003-03-16 14:35
Sender: bobyrne

Logged In: YES
user_id=151201

There is already a facility for supplying the state and event names in
form
fields called 'statemachineStateName' and 'statemachineEventName'.
If you need many buttons on the one form you can call your submit button
'statemachineEventName' and give it the event name as the value.

<input type="submit" name="statemachineEventName"
value="Event">

Or, if you need the button value to be different to the event name, you
could use client-side scripting to populate a hidden form field with the
correct event name before submitting the form.

<input type="button|submit|image"
onClick="form.statemachineEventName='Event'; form.submit();" ...
>
<input type="hidden" name="statemachineEventName"
value="">

I'll look at testing for these fields before testing for the .jsm
extension. In
the meantime there are workarounds you can use.
There is no need to stick to any one scheme to submit events to the JSM
servlet. For example you could map two different extensions to the
servlet,
such as '.evt' and '.jsm'. Those forms that use the hidden fields can
submit
to URLs ending in .evt while other forms and links can use the .jsm
extension. Since EntryServlet checks for the .jsm extension only, it will

look for the form fields if it receives any request ending with any other

extension.

Brian.



Log in to comment.




Attached File

No Files Currently Attached

Changes ( 3 )

Field Old Value Date By
status_id Open 2003-04-10 20:30 bobyrne
close_date - 2003-04-10 20:30 bobyrne
assigned_to nobody 2003-03-17 23:23 bobyrne