• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

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

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"onclic" is a typo.
Somehow I coundn't post something with "onclick" in it.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
 
Why does your bag say "bombs"? The reason I ask is that my bag says "tiny ads" and it has stuff like this:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic