Hal,

Thanks, your post is what I needed.

However, I believe there is a bug in your post. In the following code
snippet:

    if (index > interestRates.size()-1)
    {
        interestRates.add(index,new InterestRateJBean());
    }

using the add to insert a "slot" at an indexed location may cause other
locations in the ArrayList to be shifted over. This may be a problem since
there is no guarantee that the indexed properties are processed in order --
I found that some of my attributes became scrambled e.g., attribute for row
2 updated in row 1.

I replaced this code with the code below and everything appeared to work
correctly.:

        int count = Index - this.interestRates.size() + 1;

        for (int i = 0; i < count; i++) {
            this.interestRates.add(new InterestRateJBean());
        }

Basically, if I get an index of 5 then I make sure there are 6 (5 + 1) slots
in the ArrayList.

Hope this helps.

Stephen

----- Original Message -----
From: "Deadman, Hal" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 24, 2001 12:59 PM
Subject: RE: what setters do i implement in an indexed tag ?


| Ignore my previous post because I was mistaken. You don't need a
setXYZ(int
| index, XYZ x) method because struts will call the "public XYZ getXYZ(index
| i)" method and then call the appropriate set method on the bean that is
| returned. This worked for me (with last nights CVS):
|
| <logic:iterate id="interestRate" name="editInterestForm"
| property="interestRates">
| <tr>
| <td><html:hidden indexed="true" name="interestRate"
| property="interestRateId"/>
|     <html:text indexed="true" name="interestRate" property="monthId"/>
| </td>
| <td><html:text indexed="true" name="interestRate" property="rate" size="5"
| maxlength="5"/> /td>
| </tr>
| </logic:iterate>
|
| which generates field names like "interestRate[0].monthId"
|
| so struts will call form.getInterestRate(0).setMonthId(somevalue)
|
| I had this in my form class:
| ArrayList interestRates; // initialized in constructor and reset()
|
| public InterestRateJBean getInterestRate(int index)
| {
|     if (index > interestRates.size()-1)
|     {
|         interestRates.add(index,new InterestRateJBean());
|     }
|     return (InterestRateJBean) interestRates.get(index);
| }
|
| Again, I just got this to work so I may be missing something.
|
| Hal
|
| -----Original Message-----
| From: Deadman, Hal
| Sent: Tuesday, July 24, 2001 11:03 AM
| To: [EMAIL PROTECTED]
| Subject: RE: what setters do i implement in an indexed tag ?
|
|
| In the indexed tags write up at
| http://www.husted.com/about/struts/indexed-tags.htm, it only mentions the
| two types of get methods required in the action form. It doesn't mention
the
| setters that are required. It looks like the getParameterList() method is
| only used by the iterate tag. To populate the form on submit the only
setter
| needed is:
|
| public void setParameter(int index, Parameter p){...};
|
| In your case that means:
|
| public void setParameter(int index, FieldMapping f) {...};
|
| You probably don't need:
| public void setFieldMappings(java.util.Vector newFieldMappings) {
| fieldMappings = newFieldMappings;
| }
| unless you use it in your action to populate the form object before
| displaying the form jsp.
|
| I am about to try this myself so this is just a guess.
|
| Hal
|
| -----Original Message-----
| From: Warwick Boote [mailto:[EMAIL PROTECTED]]
| Sent: Tuesday, July 24, 2001 9:09 AM
| To: [EMAIL PROTECTED]
| Subject: what setters do i implement in an indexed tag ?
|
|
| I've created a page using indexed tags (neat stuff!).
| Here is what is currently working for me:
| o If i populate the form's vector, values from that vector are displayed
in
| the jsp
| Here is what it not working:
| o when the form is posted back, the vector is null (in the struts
perform()
| method)
| I suspect i haven't implemented some sort of setter within the form but i
| can't find an example as to what method should be implemented.  I've tried
| ArrayList and using parameterList instead with no different result.
| Thanks,
| Waz.
| =)
| Here are some code snippits for help:
| ---jsp---
| <logic:iterate id="mappings" name="FieldsMapForm"
property="fieldMappings">
| <html:text name="mappings" property="attributeCode" indexed="true"/> <br>
| </logic:iterate>
| ---Form---
| public class FieldsMapForm extends ActionForm {
| private String fileColCount;
| private java.util.Vector fieldMappings = new java.util.Vector();
| private String action;
| public String getFileColCount() {
| return fileColCount;
| }
| public void setFileColCount(String newFileColCount) {
| fileColCount = newFileColCount;
| }
| public void setFieldMappings(java.util.Vector newFieldMappings) {
| fieldMappings = newFieldMappings;
| }
| public java.util.Vector getFieldMappings() {
| return fieldMappings;
| }
| public FieldMapping getParameter(int index) {
| return (FieldMapping)fieldMappings.elementAt(index);
| }
| public void setAction(String newAction) {
| action = newAction;
| }
| public String getAction() {
| return action;
| }
| public void reset(ActionMapping mapping, HttpServletRequest request) {
| fileColCount = null;
| fieldMappings = new java.util.Vector();
| action = null;
| }
| }
| ---The vector contains these:---
| public class FieldMapping implements Serializable {
| private Integer fieldNumber;
| private String attributeCode;
| public void setFieldNumber(Integer newFieldNumber) {
| fieldNumber = newFieldNumber;
| }
| public Integer getFieldNumber() {
| return fieldNumber;
| }
| public void setAttributeCode(String newAttributeCode) {
| attributeCode = newAttributeCode;
| }
| public String getAttributeCode() {
| return attributeCode;
| }
| }
|


Reply via email to