permaculture playing cards*
The moose likes Struts and the fly likes how to use indexid of logic:iterate tag in struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to use indexid of logic:iterate tag in struts " Watch "how to use indexid of logic:iterate tag in struts " New topic
Author

how to use indexid of logic:iterate tag in struts

sandeepn nayak
Greenhorn

Joined: Feb 28, 2005
Posts: 3
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'
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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


Merrill
Consultant, Sima Solutions
sandeepn nayak
Greenhorn

Joined: Feb 28, 2005
Posts: 3
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

Joined: Feb 15, 2005
Posts: 4864
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

Joined: Feb 28, 2005
Posts: 3
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)
jj tt
Greenhorn

Joined: May 08, 2008
Posts: 1
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to use indexid of logic:iterate tag in struts
 
Similar Threads
Problem Passing Parameter values to action
Problem in hiding the row of data
validwhen using indexedListProperty throwing NulPointerException
access iterated struts tag in javascript
How to catch checkbox value