You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Marcel Maré <li...@webtothemax.com> on 2001/08/11 17:10:45 UTC
indexed properties weirdness. I'm desperate...
This is driving me crazy. I've spent days figuring this out. Yes, I have
read other postings about this, but obviously I'm missing something (part of
my brain perhaps).
What I want is the form bean to contain a list of objects, which have some
properties. The jsp will iterate over the objects in the list to display
it's (nested) properties in a form. Sounds simple?.... It isn't.
I just can't figure out what property getters I *have* to implement.
This is a test case I have created:
=========
The Form bean
=========
public class EditCartForm extends ActionForm {
// other stuff omitted
private ArrayList indexables = new ArrayList();
public EditCartForm() {
}
public Indexable getIndexable(int index) {
return (Indexable) indexables.get(index);
}
public List getIndexables() {
return indexables;
}
}
==========
The Indexable class that is in the list
==========
public class Indexable extends Object implements java.io.Serializable {
private String stringProp;
private Integer intObjProp;
private int intProp;
public Indexable() {
}
public Indexable( int value ) {
intProp = value;
intObjProp = new Integer(intProp);
stringProp = String.valueOf(intProp);
}
public String getStringProp() {
return stringProp;
}
public void setStringProp(String value) {
this.stringProp = value;
}
public Integer getIntObjProp() {
return intObjProp;
}
public void setIntObjProp(Integer intObjProp) {
this.intObjProp = intObjProp;
}
public int getIntProp() {
return intProp;
}
public void setIntProp(int intProp) {
this.intProp = intProp;
}
}
=======
struts-config
=======
<action path="/someAction"
type="com.webtothemax.shop.actions.AddToCartAction"
name="theForm"
scope="session"
validate="false"
=======
The jsp
=======
<html:form action="/someAction.do" >
<TABLE border="1" borderwidth="1" cellspacing="0">
<logic:iterate id="cartItem" name="theForm"
type="com.webtothemax.shop.common.CartItem" property="cart.cartItems">
<TR>
<TD><html:text name="theForm" property="indexable.stringProp"
indexed="true" /></TD>
<TD><html:text property="indexable.stringProp"
indexed="true" /></TD>
<TD><html:text property="indexable" indexed="true"
/></TD>
: This is just an example: I have only 1 of these lines in the real file.
:
: stuff omitted
:
: Note that I iterate over another collection (which has the same size)
===============================
What I would expect:
<html:text property="indexable.stringProp" indexed="true" />
to be rendered as something like :
<INPUT TYPE="TEXT" NAME="theForm.indexable[12]" VALUE="<%=
theForm.getIndexable(12).getStringProp() %>" >
Where because of omitting the "name" attribute the formbean should be
referenced.
This is what I get in reality:
When I include the name attribute:
ERROR: "No getter method for property indexable.stringProp of bean
theForm"
When I omit the name attribute:
ERROR: "No getter method for property indexable.stringProp of bean
org.apache.struts.taglib.html.BEAN"
When also omit stringProp:
ERROR: "No getter method for property indexable of bean
org.apache.struts.taglib.html.BEAN"
So, if somebody could spell it out for me, real slowly, I would be very
grateful.
TIA
Marcel Maré
WebToTheMax
E mjmare@webtothemax.com
W http://www.webtothemax.com