> * The application has registered a custom Converter that creates
> an array of objects of the appropriate type from the String-valued
> "initial" attribute.
>
> * The application then modifies the values on a per-user or
> per-request
> basis (rather than using this technique to initialize some sort of
> readonly collection).
>
> While the above conditions are technically possible, they
> don't seem like the kind of thing that real applications
> would use the "initial" attribute of a <form-property>
> element for. Is there some common use case that I am missing?
>
> > Martin Cooper
>
> Craig
Here's the specific example I ran into (and also why I proposed size= in
the first place.) (Sorry for the verboseness of this, I want to make it
clear...)
Dependent.java
package com.benefit.association;
public class Dependent {
private String lastName;
private String firstName;
private String middleName;
private String dob;
private String gender;
private String relationship;
public void reset() {
lastName = null;
firstName = null;
middleName = null;
dob = null;
gender = null;
relationship = null;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return firstName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getMiddleName() {
return middleName;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getDob() {
return dob;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getGender() {
return gender;
}
public void setRelationship(String relationship) {
this.relationship = relationship;
}
public String getRelationship() {
return relationship;
}
}
struts-config.xml
<form-bean name="dependentlistForm"
type="com.benefit.association.struts.forms.ValidatorForm">
<form-property name="dependents"
type="com.benefit.association.Dependent[]"
initial="{"", "", "", "", "", "", "", "", "", ""}
/>
</form-bean>
.
.
.
<action name="dependentlistForm"
type="com.benefit.association.struts.actions.DependentListAction"
input="/dependentlist.jsp" scope="session"
path="/dependentlist">
<forward name="/kea/coverage" path="/kea/coverage.jsp" />
<forward name="/krta/coverage" path="/krta/coverage.jsp" />
<forward name="/swof/coverage" path="/swof/coverage.jsp" />
</action>
And my dependentlist.jsp has in part:
<html:form action="/dependentlist">
<TABLE><TR><TD>Last Name</TD><TD>First
Name</TD><TD>MI</TD><TD>Relationship</TD><TD>Date of
Birth<BR>MM/DD/YYYY</TD><TD>Gender</TD></TR>
<logic:iterate id="dependents" name="dependentlistForm"
property="dependents" type="com.benefit.association.Dependent">
<TR><TD><html:text name="dependents" property="lastName" indexed="true"
maxlength="30" size="30"/></TD>
<TD><html:text name="dependents" property="firstName" indexed="true"
maxlength="30" size="30"/></TD>
<TD><html:text name="dependents" property="middleName" indexed="true"
maxlength="1" size="1"/></TD>
<TD><html:select name="dependents" property="relationship"
indexed="true">
<html:option value="S">Spouse</html:option>
<html:option value="C">Child</html:option>
</html:select></TD>
<TD><html:text name="dependents" property="dob" indexed="true"
maxlength="10" size="10"/></TD>
<TD><html:select name="dependents" property="gender" indexed="true">
<html:option value="M">Male</html:option>
<html:option value="F">Female</html:option>
</html:select></TD></TR>
</logic:iterate>
What happens (with cloning) is this:
The first time through, FormPropertyConfig correctly calls the converter
I had registered for Dependent (which creates a new instance regardless
of the initialization value) and correctly sets up the array. At the
end of the registration process, the form is removed from session scope.
However, the next time someone requests a dependentlistForm, it gets a
cloned copy of the dependents array, which means that although the array
is new, the elements are the same as from the last form, including
values filled in by the user.
Does this clarify how it can happen?
James
Now I have a form:
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>