I guess its time to learn struts-el, JSTL (remove inline scripting) and
dynaforms!!! Man!! This just never seems to end. The next up challenege
to get the damn checkbox retain their states!!. Using array for checkbox
to retain an ID
Something like this
<input type="checkbox" value="6"name="stateId[0]" />
<input type="checkbox" value="7"name="stateId[1]" />
<input type="checkbox" value="8"name="stateId[2]" />

So which ever checkbox s checked its value is set.
Any clues?

-----Original Message-----
From: Mark Lowe [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 28, 2003 1:09 AM
To: Struts Users Mailing List
Subject: Re: Index properties (once again)


That's okay Rajat as I said I know what its like to up against the 
wire..

I've found ArrayList works better in dynaActionForms especially if 
you're dynamically generating forms. I think this because its a big fat 
pain in the arse to create new dynabeans (have a play with bean utils 
for a day and you find this out).

When setting the size dynamically you need to scope the form to session.

<action path="/myaction" scope="session" ..

I use arraylist as the form property type, i don't think that arrays 
work but i could be wrong

<form-property name="myprop" type="java.util.ArrayList" /> [notice you
dont set the size]

then in your action when your loading the form

ArrayList list = ...

theForm.set("myprop",list);

and also (I guess this shouldn't be required but it is)...

request.setAttribute("myprop",list);

then

<logic:iterate id="prop" name="myForm" property="myprop">
        <html:text name="prop" property="foo" indexed="true" />
</logic:iterate>

I guess you could apply the same principles using non dynamic action 
form. I imagine that using an array rather than arrayList should work 
too.

Cheers Mark


On Tuesday, October 28, 2003, at 02:31 AM, Rajat Pandit wrote:

> 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]


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

Reply via email to