File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts:: referring indexId of logic:iterate from javascript call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts:: referring indexId of logic:iterate from javascript call" Watch "Struts:: referring indexId of logic:iterate from javascript call" New topic

Struts:: referring indexId of logic:iterate from javascript call

Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi everybody,
In Ted Husted's Struts Tips site,
<html:hidden property="dispatch" value="error"/>
<SCRIPT>function set(target) {document.forms[0].dispatch.value=target;}</SCRIPT>
<html:submit onclic="set('save');">SAVE</html:submit>
<html:submit onclic="set('create');">SAVE AS NEW</html:submitl>
<html:submit onclic="set('delete);">DELETE</html:submit>
one part of the tutorial shows a way to use javascript to set value in ActionForm. Smart. I wanted to try the same thing and ran into a problem:
function set(target) {
document.forms[0].source.value = target;
<html:hidden property="source" value="notSet" />
<logic:iterate id="content" name="myBean" property="myProp" indexId="idx">
<html:submit onclic="set('<%=idx%>');" property="buttonName" value="another value" />

I want to use logic:iterate tag's indexId attribute to make that call.
The result is that everyting, including <% tag, shows up same as the source code. I tried converting indexId to int, again to String, and everything I can think of. Still no good result.
Is there any way to achieve this?
I appreciate your suggestions and comments.

Thank you.

/*<br /> * Quants Inc.<br /> * Engineer<br /> *<br /> * Shin Hashitani<br /> *<br /> * <a href="" target="_blank" rel="nofollow"></a><br />*/
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
"onclic" is a typo.
Somehow I coundn't post something with "onclick" in it.
Bill Siggelkow
Ranch Hand

Joined: Jun 27, 2001
Posts: 57
I believe all you need to do is fomat the RT expression as a string concatenation for the onclick attribute:

Bill Siggelkow
Jade Cove Solutions
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
Hi Bill,
It worked!!
It would have been a nightmare if I couldn't solve this part.
Thank you!!
Shin Hashitani
Ranch Hand

Joined: Dec 04, 2001
Posts: 54
I apologize for digging up an old thread.
I am still in the same project, and encountered an I-should've-thought-bout-this problem. I want to ask you how to manage this problem if you were me:
The basic technique is:
The form has a hidden element which is linked to a property in the action form.
onclick event handler calls a javascript function that will set a particular value to the hidden form.
A click of a certain button is traceable from action form, without depending on value property of the submit button.
A page can have a lot of form elements. And very often, espacially in server-side technology enabled system, the number of forms cannot be determined at compile time. So, using.
Is not a dependable way to access a particular form by javascript.
So, I thought
Is a better way to do it.

However, html:form tag does not allow me to set name of the form.
how do I manage this?
Or, how do you manage this if you were me?

I appreciate any comment or suggestion.
Thank you.
Sandip Chaudhuri

Joined: Dec 27, 2004
Posts: 26
try this dunno if it will work for u

<html:javascript formName="FormTrial" cdata="false" dynamicJavascript="true" staticJavascript="false"/>

cdata not to show the validation code
Jose Pereira

Joined: Dec 10, 2002
Posts: 12
I found this

<html:form action="" styleId="your_form_name">

this creates a id=your_form_name inside the form tag

but i still canta find a way to execute a deferent html:form from inside this one : /
[ January 13, 2005: Message edited by: Jose Carlos ]
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Whats the name of the formBean that is associated to the action in the config file? I've been using that it works for me.

Although I'm working on something where I'll have multiple copies of the same form class on the page at once and I don't know how it would handle that (if I can even get it to work).

Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

The standard used on projects I have been is


to get a reference to a document element. We then specify the "styleId" attribute of any struts html tag elements and the "id" attribute of any standard HTML elements, e.g.

<html:text property="name" styleId="personName" />

<input type="text" name="addressLine1" id="personAddr1" />

In JavaScript:

var nameElement = document.getElementById("personName");
var addrElement = document.getElementById("personAddr1");

Junilu - [How to Ask Questions] [How to Answer Questions]
I agree. Here's the link:
subject: Struts:: referring indexId of logic:iterate from javascript call
jQuery in Action, 3rd edition