• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shin Hashitani
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shin Hashitani
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"onclic" is a typo.
Somehow I coundn't post something with "onclick" in it.
 
Bill Siggelkow
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe all you need to do is fomat the RT expression as a string concatenation for the onclick attribute:
 
Shin Hashitani
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bill,
It worked!!
It would have been a nightmare if I couldn't solve this part.
Thank you!!
 
Shin Hashitani
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7598
53
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic