You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Solomon Gorlick <sg...@rescapayments.com> on 2003/06/19 23:18:42 UTC
problem passing 's indexId to 's onchange
Hello everyone,
I am a little new at using Struts, so my apologies if this is a newbie
question. I did check the archives and even found a similar query, but
unfortunately no posted solution.
In any event, this is what I have:
1) An iterate loop that loops through a list of selected classes (the size
of the loop can be dynamic). This seems to be working fine.
2) For each of these selected classes I want to make a <html:select> list
with <html:options> coming from an attribute collection. This works, but I
have to have hard-coded "collections" and "name" properties (e.g.
payeeClassLists0, payeeClassLists1 and payeeClassLists2) for each
<html:options>. So now I have 3 "hard-coded" sections dilineated by the
<logic:equal> blocks. Although this works because I know I will only have a
maximum of 3 lists, it is pretty ugly and doesn't scale well. Any way to
use the indexId in the "name" and "collection" properties of the
<html:options> tag?
3) Finally, I wanted to be able to re-submit this page on the onChange of
any of the created <html:select>s (and then in the Action class repopulate
the selected classes and the appropriate collections based on the CHANGED
select list). I have "achieved" this in working code below, but as for 2) I
have to do this on a per-list basis (again the need for the 3 <logic:equal>
blocks). Any way to get the indexId into part of the "onchange" of the
<html:select> tag?
Of course I am trying to use the struts tags instead of scrapping this all
and doing it in "pure" JSP. Any thoughts would be appreciated. I really
hope I am doing something silly here. ;)
Here is my working - but duplicate - code:
(notice that only <html:select>'s onchange's changedFieldName.value and
<html:options>'s name and collection change (like the indexId) with each
"level" below:
<logic:iterate name="pyrPayeeEditForm" property="payeeClassHierarchy"
id="payeeClass" indexId="itemCounterPayeeClass">
<!--for class level 0-->
<logic:equal name="itemCounterPayeeClass" value="0">
<html:select name="payeeClass" property="payeeClassId"
onchange="javascript:document.forms[0].changedFieldName.value='0';">
<html:options name="payeeClassLists0" collection="payeeClassLists0"
property="payeeClassId" labelProperty="name"/>
</html:select>
</logic:equal>
<!--for class level 1-->
<logic:equal name="itemCounterPayeeClass" value="1">
<html:select name="payeeClass" property="payeeClassId"
onchange="javascript:document.forms[0].changedFieldName.value='1';">
<html:options name="payeeClassLists1" collection="payeeClassLists1"
property="payeeClassId" labelProperty="name"/>
</html:select>
</logic:equal>
<!--for class level 2-->
<logic:equal name="itemCounterPayeeClass" value="2">
<html:select name="payeeClass" property="payeeClassId"
onchange="javascript:document.forms[0].changedFieldName.value='2';">
<html:options name="payeeClassLists2" collection="payeeClassLists2"
property="payeeClassId" labelProperty="name"/>
</html:select>
</logic:equal>
</logic:iterate>
=========================
I would prefer to use an abbreviated version of the above that is something
like this (thought this doesn't work):
<logic:iterate name="pyrPayeeEditForm" property="payeeClassHierarchy"
id="payeeClass" indexId="itemCounterPayeeClass">
<!--for ALL class levels -->
<html:select name="payeeClass" property="payeeClassId"
onchange="javascript:document.forms[0].changedFieldName.value='<%=indexId%>'
;">
<html:options name="payeeClassLists<%=indexId%>"
collection="payeeClassLists<%=indexId%>" property="payeeClassId"
labelProperty="name"/>
</html:select>
</logic:iterate>
Thanks for any help.
regards,
Solomon
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org