Hi Rajat,

You could use an Array.  If your form is in the session, as opposed to the
request, the array will never go away, so the array will retain its size.
I can't do that in our app as our UI presents a "spreadsheet" and allows
the user to add and remove rows.  For that reason, I use an ArrayList since
I can easily resize it on the fly.

As far as creating an Array with the correct size, I don't believe that we
have any control over the sequence in which Struts populates the
ActionForm.  So we couldn't submit the array size from the browser.

Glad that you found the referenced threads useful :-)
Nick





                                                                                       
                                                
                      "Rajat Pandit"                                                   
                                                
                      <[EMAIL PROTECTED]        To:       "'Struts Users Mailing 
List'" <[EMAIL PROTECTED]>                
                      upinc.com>               cc:                                     
                                                
                                               Subject:  RE: Index properties (once 
again)                                             
                      10/27/2003 09:31                                                 
                                                
                      PM                                                               
                                                
                      Please respond to                                                
                                                
                      "Struts Users                                                    
                                                
                      Mailing List"                                                    
                                                
                                                                                       
                                                
                                                                                       
                                                




Hello all,
I finally managed to solve the problem, and now that I know it all seems
so damn awfully simple!!! , I wish the docs had explained it in a much
simpler manner. But I guess it was more about the form and ActionForm
thing than about the indexed properties. I am writing a HOWTO on all
possible variations of indexed properties now. Shall post it on the
mailing list for your review.
Thanks a lot nick, for the pointers, it was a great help.

Just one more question, it works just fine if I define it as an
ArrayList, but in case I want to use it as an array, how do I workaround
for the size. One way is to assume a higest upper limit. (which I think
is lame) Is there someone I can inform the actionForm about the last
value of the index of the <logic:iterate.. Tag ... I mean this could
sound rather silly...but just to know is there a possibility?

Thanks again for all ur time. And yes mark! Thanks for all the kick in
the butt!! Helped me think rationally :D


-----Original Message-----
From: Rajat Pandit [mailto:[EMAIL PROTECTED]
Sent: Sunday, October 26, 2003 9:39 PM
To: [EMAIL PROTECTED]
Subject: Index properties (once again)


Hello sorry for posting the same question again and again. But I seem to
have gained something on this. Now I have a few (more) questions. Maybe
someone could help me figure out what or where I am getting it wrong.


This is the case. I have a product, with different states(checbox) and
each state has to have a bidAmount (text area) and a transaction
type(radio button). I want the form to be generated such that for
validation.

a. I can check If the checkbox(for the state) has been checked the
bidAmount and transaction type has been selected.

Now my question is,
a. in the action form. Do I need to defind the bidAmount as an array
b. I didn't know about this until know, but are only String type allowed
in actionform ( ihavent read about this anywhere except on one of the
posts in this mailing list) c. I have set the setter and getter for
(lets take the example of bidAmount only) like this.

    public String getBidAmount(int index) {
            String tmp = new String();
            System.err.println("Value of index: " + index);
            try {
                tmp = bidAmount[index];
            } catch (Exception e) {
                System.err.println("Error: " + e.getMessage());
            }
        return tmp;

    }

    public void setBidAmount(int index, String value) {
        System.err.println("index: " + index);
        System.err.println("Value: " + value);
        System.err.println("------------------");
        this.bidAmount[index] = value;
    }



And the corresponding jsp tags as follows.

        <logic:iterate id="state" name="STATES" indexId="currIdx">

        <tr bgcolor="#F8F8F8">
          <td align="left" valign="top">
            <html:multibox property="stateId" styleClass="flat">
<bean:write name="state" property="id" />
            </html:multibox> <bean:write name="state" property="name" />
          </td>
          <td >
                <html:text name="bidForm"
property='<%="bidAmount["+currIdx+"]"%>'  styleClass="flat" size="3"  />
          </td>

          <td align="center">
            BC <html:radio name="bidForm" property="mode" value="2"
titleKey="app.bcall"  indexed="true" styleClass="flat" />
            | SC <html:radio name="bidForm" property="mode" value="1"
titleKey="app.scall"  indexed="true"  styleClass="flat" />
          </td>

          <td align="right">
            <bean:write name="state" property="buyingCall" ignore="true"
/>
          </td>
          <td align="right">
            <bean:write name="state" property="sellingCall"
ignore="true" />
           </td>

        </tr>
        </logic:iterate>



I know the the inline scriptlet is very ugly, but this was the only way
I could get it to call the index number in the getter method. However
the desperate attempt (try and catch) makes the form work (not much use)
I cant get the the setter to set the values in the individual array, and
get a stack trace error instead.

I am not really sure where Is wrong and non or the documentataion define
things very clearly (or maybe I am poor in comprehension) Apologies
again to people who think I am bothering them by posting again and
again, but this is my last hope!!

Hope someone helps!
(ps: once I am through with this, I shall write my own HOW TO for the
indexed properties and its use)

Rajat Pandit | [EMAIL PROTECTED]
+91 612 3117606
[ Developer and Part Time Human Being]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to