struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adam K" <ada...@gmail.com>
Subject Struts textfield +Iterated list +retrieving user changed value from form.
Date Tue, 03 Oct 2006 18:41:59 GMT
I am working with struts 1.2.9 and trying to use the iterate function.  I
seem to be having a problem extracting the value from a text field inside an
iterated loop.  I am able to get/set values thare are being placed simply
into html, but run into difficulties when working with the text fields.  I
am able to set the values into the text field, but unable to pull them out
when in the action code of the form.  The following is what I have used for
code thus far:

If I understand the struts wiki page that I was pointed to properly the name
in the text must be the same as the id, but when I would try that I would
simply receive index out of bounds errors - that was making all references
to counter called results.
Results is an object that is holding a product, description, and
numProducts.


<logic:notEmpty name="ProdSelectionForm" property="results">
    <logic:iterate name="ProdSelectionForm" property="results" id="counter">
    <tr>
        <td>    <bean:write name="counter" property="product" />
        </td>
        <td>    <bean:write name="counter" property="description" />
        </td>
        <td>    <html:text  name="counter" property="numProducts"
indexed="true" size="15" maxlength="15"/>    </td>
    </tr>
    </logic:iterate>
</logic:notEmpty>


This is in the Action portion - well it is a snippet of the entire thing.

ProdSelectionForm prodSelection = (ProdSelectionForm) form;

int count = 0;
  // take in the number of items in the order ArrayList and iterate through
them
  while(count < order.getProductsSize() )
  {
     Product p = null;
     // pull the product from the order at each position to manipulate them.
     p = (Product) products.get(count);

     // set the order amount to be what the old amount was on top of the
amount that is currently on the screen
     p.setNumProducts(p.getNumProducts() + 1 + prodSelection.getNumProducts
());
     // the below code was to test and see if the variable would change at
all, with the +100 it would increment the amount on the screen by 100
everytime the action was called, so that lead me to believe that I am
setting the values right.
     //p.getNumProducts() + 100 + prodSelection.getNumProducts() );

     // set the product back into the product arraylist so it can be passed
to the
     products.set(count, p);
     count++;
  }

//set the product arrayList back into order so it can be presented on the
screen.
order.setProducts(products);

And finally for the form I have the following relevant code:

    /**
     * @return Returns the numProduct.
     */
    public int getNumProducts() {
        return numProducts;
    }
    /**
     * @return ReturnsnumProduct at the specified index
     */
    public int getNumProducts(int index) {
        Product p = (Product) results.get(index);
        return p.getNumProducts();
    }

    /**
     * @param numProducts The numProduct to set.
     */
    public void setNumProducts(int numProducts) {
        this.numProducts = numProducts;
    }

I seem to be able to pull the value from the page, but it won't pull the
changed values - that is to say it will only pull the value that was there
when the page was first presented regardless of anything that I type.
Could someone point me to where I am having a brain fart.  Ps. I have been
made aware that I should be using JSTL, but would welcome any other critisms
the list might have to offer.

thanks in advance for your time on this matter.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message