How can I use "indexId" in logic:iterate of struts?

Z

Zhao

I need to use the index number to construct a parameter of a script
call like
following (the second para of doSubmit)

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="index">
<tr>
...
<html:button property="add" value="Add to cart"
indexed="true" onclick="doSubmit(this.form,'<%=index%>')"/></td>
</tr>
....
</logic:iterate>

I got error

javax.servlet.ServletException: No getter method for property row of
bean org.apache.struts.taglib.html.BEAN

How can I access the index defined by "indexId" attribute of
"logic:iterate"?

thanks
 
D

David W. Burhans

I need to use the index number to construct a parameter of a script
call like
following (the second para of doSubmit)

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="index">
<tr>
...
<html:button property="add" value="Add to cart"
indexed="true" onclick="doSubmit(this.form,'<%=index%>')"/></td>
</tr>
...
</logic:iterate>

Use the <bean:write> custom tag to insert the value of index. Here is an example:

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
<td>
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,
'<bean:write name="BambooItemIndex"/>)"/>
</td>
</tr>
</logic:iterate>
 
Z

Zhao

David, I really appreciate your suggestion but I got following error
(similar to what I got before)

javax.servlet.ServletException: No getter method for property row of
bean org.apache.struts.taglib.html.BEAN
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
at org.apache.jsp.bambooList_jsp._jspService(bambooList_jsp.java:272)
....


Here is the code

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
...
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,<bean:write
name='BambooItemIndex'/>)"/></td>
</tr>

....


Any thought?

thanks

zhao
 
Z

Zhao

David, sorry: that error was caused by something else. Now it
runs but the "<bean:write name=index/>" is never evaluated.

I see

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, '<bean:write name=BambooItemIndex/>')">
</td>

when view source of the generated html code.

Are you sure that we can use nested tags in this way?

thanks

Zhao
 
A

Andrew S.

David, sorry: that error was caused by something else. Now it
runs but the "<bean:write name=index/>" is never evaluated.

I see

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, '<bean:write name=BambooItemIndex/>')">
</td>

when view source of the generated html code.

Are you sure that we can use nested tags in this way?

thanks

Zhao


Use the <bean:write> custom tag to insert the value of index. Here is an example:

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
<td>
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,
'<bean:write name="BambooItemIndex"/>)"/>
</td>
</tr>
</logic:iterate>

It's not possible to nest tags in this manner. The onclick attribute
expects a string. <%= index %> evaluates to an Integer. Try
something like:
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form, <%= index.toString() %>)" />

Andrew
 
Z

Zhao

Andrew, really appreciate your help but I still get the following when
viewing source (the generated html)

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, <%= index.toString() %>)"> </td>

I think the problem is the double quote - it prevents jsp/struts
from evaluating the anything within the quote...

Any thought to get around?

How do people use any index in logic:iterate normally?

thank

Zhao

David, sorry: that error was caused by something else. Now it
runs but the "<bean:write name=index/>" is never evaluated.

I see

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, '<bean:write name=BambooItemIndex/>')">
</td>

when view source of the generated html code.

Are you sure that we can use nested tags in this way?

thanks

Zhao


(e-mail address removed) (Zhao) wrote in message I need to use the index number to construct a parameter of a script
call like
following (the second para of doSubmit)

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="index">
<tr>
...
<html:button property="add" value="Add to cart"
indexed="true" onclick="doSubmit(this.form,'<%=index%>')"/></td>
</tr>
...
</logic:iterate>


Use the <bean:write> custom tag to insert the value of index. Here is an example:

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
<td>
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,
'<bean:write name="BambooItemIndex"/>)"/>
</td>
</tr>
</logic:iterate>

It's not possible to nest tags in this manner. The onclick attribute
expects a string. <%= index %> evaluates to an Integer. Try
something like:
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form, <%= index.toString() %>)" />

Andrew
 
C

Chris Smith

Zhao said:
Andrew, really appreciate your help but I still get the following when
viewing source (the generated html)

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, <%= index.toString() %>)"> </td>

I think the problem is the double quote - it prevents jsp/struts
from evaluating the anything within the quote...

Any thought to get around?

There is, actually, no solution. JSP 2.0 will provide an alternate
syntax for specifying parameters, which will allow this kind of thing.
An early access release of JSP 2.0 is available in the Tomcat 5.x
series.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Z

Zhao

Chris, I saw something like this

<!-- indexedtest5.jsp -->
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<body>
<html:form action="indexedtest5.do">
<logic:iterate name="stringbean" property="stringArray" id="foo"
indexId="ctr">
<html:text name="stringbean"
property='<%= "labelValue[" + ctr + "].label" %>' />
</logic:iterate>
<html:submit property="submitValue">Submit Changes</html:submit>
</html:form>
</body>
</html>

in page

http://jakarta.apache.org/struts/faqs/indexedprops.html

but it didn't work in my page...

I think there must be a solution out there...

thanks

mark

Chris Smith said:
Zhao said:
Andrew, really appreciate your help but I still get the following when
viewing source (the generated html)

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, <%= index.toString() %>)"> </td>

I think the problem is the double quote - it prevents jsp/struts
from evaluating the anything within the quote...

Any thought to get around?

There is, actually, no solution. JSP 2.0 will provide an alternate
syntax for specifying parameters, which will allow this kind of thing.
An early access release of JSP 2.0 is available in the Tomcat 5.x
series.
 
C

Chris Smith

Zhao said:
Chris, I saw something like this

<html:text name="stringbean"
property='<%= "labelValue[" + ctr + "].label" %>' />
but it didn't work in my page...

I think there must be a solution out there...

The above is an rtexprvalue attribute. That allows you to write Java
code in place of the ENTIRE attribute value. You were trying to write
Java code in place of only part of the attribute value, which doesn't
work. Also, check to ensure that the tag you're using accepts runtime
values for that attribute. Since there's a performance cost, not all
tags are specified to allow this.

My comment was about not being able to nest one tag inside another,
which is definitely not possible, until JSP 2.0.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
A

Andrew S.

Andrew, really appreciate your help but I still get the following when
viewing source (the generated html)

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, <%= index.toString() %>)"> </td>

I think the problem is the double quote - it prevents jsp/struts
from evaluating the anything within the quote...

Any thought to get around?

How do people use any index in logic:iterate normally?

thank

Zhao

David, sorry: that error was caused by something else. Now it
runs but the "<bean:write name=index/>" is never evaluated.

I see

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, '<bean:write name=BambooItemIndex/>')">
</td>

when view source of the generated html code.

Are you sure that we can use nested tags in this way?

thanks

Zhao


(e-mail address removed) (David W. Burhans) wrote in message (e-mail address removed) (Zhao) wrote in message I need to use the index number to construct a parameter of a script
call like
following (the second para of doSubmit)

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="index">
<tr>
...
<html:button property="add" value="Add to cart"
indexed="true" onclick="doSubmit(this.form,'<%=index%>')"/></td>
</tr>
...
</logic:iterate>


Use the <bean:write> custom tag to insert the value of index. Here is an example:

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
<td>
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,
'<bean:write name="BambooItemIndex"/>)"/>
</td>
</tr>
</logic:iterate>

It's not possible to nest tags in this manner. The onclick attribute
expects a string. <%= index %> evaluates to an Integer. Try
something like:
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form, <%= index.toString() %>)" />

Andrew

Duh - don't know what I was thinking...
<jsp:useBean id="posVEH" scope="request" class="Integer" />
<jsp:useBean id="posNDX" scope="request" class="Integer" />
<html:select property="<%= Globals.getVehicleMakeProperty(posVEH) %>"
onchange='<%= "onMakeChanged(" + posVEH.toString() + ")"%>'
tabindex="<%= posNDX.toString() %>" >

Assuming posVEH value is 2 and posNDX is 5 this generates the
following opening select tag:
<select name="vehicle[2].make" tabindex="5"
onchange="onMakeChanged(2)">

Hope this helps (this time)!

Andrew
 
Z

Zhao

I don't quite get your idea, Andrew.

I got around by using "<input" tag mixing with Struts tags.

To get the index, I added a number field in the bean and
create the number when I fill the collection in my action class
using a counter. Then I used "<bean:write ...>" to get the index field
as index which combines with some prefix as the id of the "<input" tag
so that I can access it from js using getElementById.

I still have no idea how I can get an index in a pure Struts iterating loop.

But thank you all for the help!

Zhao




Andrew, really appreciate your help but I still get the following when
viewing source (the generated html)

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, <%= index.toString() %>)"> </td>

I think the problem is the double quote - it prevents jsp/struts
from evaluating the anything within the quote...

Any thought to get around?

How do people use any index in logic:iterate normally?

thank

Zhao

(e-mail address removed) (Zhao) wrote in message David, sorry: that error was caused by something else. Now it
runs but the "<bean:write name=index/>" is never evaluated.

I see

<input type="button" name="add[0]" value="Add to cart"
onclick="doSubmit(this.form, '<bean:write name=BambooItemIndex/>')">
</td>

when view source of the generated html code.

Are you sure that we can use nested tags in this way?

thanks

Zhao


(e-mail address removed) (David W. Burhans) wrote in message (e-mail address removed) (Zhao) wrote in message I need to use the index number to construct a parameter of a script
call like
following (the second para of doSubmit)

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="index">
<tr>
...
<html:button property="add" value="Add to cart"
indexed="true" onclick="doSubmit(this.form,'<%=index%>')"/></td>
</tr>
...
</logic:iterate>


Use the <bean:write> custom tag to insert the value of index. Here is an example:

<logic:iterate id="BambooItem" name="BambooListForm"
property="bambooItemList" indexId="BambooItemIndex">
<tr>
<td>
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form,
'<bean:write name="BambooItemIndex"/>)"/>
</td>
</tr>
</logic:iterate>

It's not possible to nest tags in this manner. The onclick attribute
expects a string. <%= index %> evaluates to an Integer. Try
something like:
<html:button property="add" value="Add to cart" indexed="true"
onclick="doSubmit(this.form, <%= index.toString() %>)" />

Andrew

Duh - don't know what I was thinking...
<jsp:useBean id="posVEH" scope="request" class="Integer" />
<jsp:useBean id="posNDX" scope="request" class="Integer" />
<html:select property="<%= Globals.getVehicleMakeProperty(posVEH) %>"
onchange='<%= "onMakeChanged(" + posVEH.toString() + ")"%>'
tabindex="<%= posNDX.toString() %>" >

Assuming posVEH value is 2 and posNDX is 5 this generates the
following opening select tag:
<select name="vehicle[2].make" tabindex="5"
onchange="onMakeChanged(2)">

Hope this helps (this time)!

Andrew
 
Joined
Jul 7, 2009
Messages
1
Reaction score
0
IndexID is an Integer

Easy solution:

indexID is instantiated as an Integer.

If you need to reference it as a literal, use .toString() or .intValue() as you see fit.

This will allow you to use it in a scriptlet <%= %> notation, which is allowed inside tags.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top