• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to use indexid of logic:iterate tag in struts

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am having one logic:iterate tag as follows

<logic:iterate id="row" property="dtlFormBean" name="IndexMainForm" indexId="ctr" type="com.san.IndexForm">
<td width="25%"><html:text onchange='<%="setModified("+ ctr +");"%>' name="row" property="indexFrom" indexed="true"/></td>
<td width="25%"><html:text onchange='<%="setModified("+ ctr +");"%>' name="row" property="indexTo" indexed="true"/></td>
<html:hidden name="row" property="dtlModified" indexed="true"/>
</logic:iterate>


i have written one java script to set the dtlModified value

function setDtlModified(ctr)
{
document.forms[0].dtlModified[ctr].value='Y';
}

but this is giving me javascript error and the dtlModified value
is not set to 'Y'
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look carefully at the name of the javaScript function you created, and the function being called by the onchange event. They are not the same.

Merrill
 
sandeepn nayak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry that is a misake i did while posting
i am posting the new one


<logic:iterate id="row" property="dtlFormBean" name="IndexMainForm" indexId="ctr" type="com.san.IndexForm">
<td width="25%"><html:text onchange='<%="setDtlModified("+ ctr +");"%>' name="row" property="indexSlabFrom" indexed="true"/></td>
<td width="25%"><html:text onchange='<%="setDtlModified("+ ctr +");"%>' name="row" property="indexSlabTo" indexed="true"/></td>
<html:hidden name="row" property="dtlModified" indexed="true"/>
</logic:iterate>


i have written one java script to set the dtlModified value

function setDtlModified(ctr)
{
document.forms[0].dtlModified[ctr].value='Y';
}

but this is giving me javascript error and the dtlModified value
is not set to 'Y'


The corresponding html generated is as follows

<td><input type="text" name="row[0].indexSlabFrom" value="" onchange="setDtlModified(0);" class="textfield" ></td>
<td><input type="text" name="row[0].indexSlabTo" value="" onchange="setDtlModified(0);" class="textfield" ></td>

I am displaying this data in tabular form
My problem is how can i use this index "ctr" in a java script
For eg.

Say i want to total up all the values of indexSlabFrom and assign it to
another textbox of sum
How can i do this in javascript

Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't what you asked, but the first thing I'd do is change the "id" attribute of the logic:iterate tag to "dtlFormBean" to match the property. This way your field names will map to "dtlFormBean[0].indexFrom" and "dtlFormBean[0].indexTo". Then, as long as you have an indexed getter for dtlFormBean, Struts will populate your form correctly.

Regarding javaScript: your hidden field will resolve to the name row[0].dtlModified. If you want to change his field, you should reference it correctly as in:



Once you know how Struts is resolving it's tags into regular html tags, javascript in struts is the same as javascript with any html.

To get the sum, i'd use the DOM API within javaScript to iterate through the input fields and add up the values. If you don't know how to do that, you will need to increase your javaScript knowledge before continuing. Here is a link to one good tutorial:

http://www.howtocreate.co.uk/tutorials/index.php?tut=0&part=24
[ March 01, 2005: Message edited by: Merrill Higginson ]
 
sandeepn nayak
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill

My problem is solved

Well i can also use id="row" and i am using the Lazy initialisation
for setRow and getRow in my Form and everything is working fine
The only problem i had was with the javascript and that too is resolved
I am now using

document.forms[0].elements['row['+ctr+'].dtlModified'].value='Y';

I am not that strong in javascript thanks for the link ...will study from there

Please send any other links related to struts(advanced features of struts which i can use in my project) and other technologies which i can use with struts

Thanks
Sandeep
(snayakn@yahoo.co.in)
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

i tried running this in my javascript function
document.forms[0].elements['row['+ctr+'].dtlModified'].value='Y'

but i am always getting row undefined. Any idea why i am getting this problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic