This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Author

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:
<script>
function set(target) {
document.forms[0].source.value = target;
}
</script>
...
<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" />
...
</logic:iterate>

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 /> * hashitani@quants.co.jp<br /> * <a href="http://www.quants.co.jp" target="_blank" rel="nofollow">www.quants.co.jp</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.
document.forms[0].myElement.value
Is not a dependable way to access a particular form by javascript.
So, I thought
document.formName.myElement.value
Is a better way to do it.

However, html:form tag does not allow me to set name of the form.
Well.....
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
Greenhorn

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
Greenhorn

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

<html:form action="Action.do" 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).

-Tad
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

The standard used on projects I have been is

document.getElementById(id)

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: http://aspose.com/file-tools
 
subject: Struts:: referring indexId of logic:iterate from javascript call