Problem with multiple submit buttons on Struts form

  • Thread starter Klaas van Gelder
  • Start date
K

Klaas van Gelder

Hi all,
I have a form (html:form) which dynamically displays a number of
database records prefixed by a checkbox (html:multibox).
The user can select a number of records and carry out some action for
the selection. The number of possible actions is also dynamic and is
determined by the call:
userData.getHandler().getButtonsToShow()

For each of the possible actions, I include a submit button
(html:submit) in the form. The use of multiple submitbuttons is
necessary because of the checkboxes which also must be included within
the form (otherwise separate forms for each submit button could be
used). So now I need a wayt to indentify each submitbutton uniquely for
the Struts action.
The only way I can think of to achieve this is the use of a hidden
field, here with property="aktieVoorSelectie". The value of this
property is set with a Javascript function (zetAktie), which receives
the "key" of the pressed button as an argument.
But this code does not work !!! The scriptlet <%=key.toString() %> is
not translated but appears literally in the generated HTML source !
the code DOES work if a static number is passed to the JS function.

The real problem is that the submit buttons are created
on the fly, because the number of possible actions is
determined by a call to some business method.
Therefore, I need to pass an argument to the Javascript-function
dynamically. I try to use a scriptlet for this, and that is
where the problem arises !!!
The scriptlet in the JS function argument is not resolved
but appears literally in the generated HTML !

So my real question is: is there a method to pass the value of
key.toString() to the JS function ?
Greetz,
Klaas



<html:form action="/DoSomething">
<html:hidden property="aktieVoorSelectie" value=""/>
<%
//loop over knoppen
int[] knoppen = userData.getHandler().getButtonsToShow();
for (int i=0; i<knoppen.length; i++) {
Integer key = new Integer(knoppen);
%>
<html:submit
styleClass="button_blue"
value="<%= optionDataBean.getAktieButtonData(key).getCaption() %>"
title="<%= optionDataBean.getAktieButtonData(key).getAltText() %>"
onclick="zetAktie(<%=key.toString() %>)"/> <% //THIS LINE DOES
NOT WORK
}
%>

</html:form>
 
Joined
Sep 27, 2006
Messages
2
Reaction score
0
Struts Form multiple submit and hidden field set

You can do it as:

<html:form>
<html:hidden property="operation" value="">
<html:submit styleClass="buttonz" value=" Ok " onclick= "document.mangeUserFormBean.operation=create" />
<html:submit styleClass="buttonz" value="Cancel" onclick= "document.mangeUserFormBean.operation=cancel" />
</html:form>
 
Joined
Sep 27, 2006
Messages
2
Reaction score
0
where manageUserForm is name of your form (you cn get it from struts-config.xml) in which you have multiple sub,mit buttons and hidden field
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top