Atta,

It sounds to me like you have it.  As long as your names match up, it
should work fine.  Ajay has given a full code example that looks good.

Nick



                                                                                       
                                                
                      "atta-ur rehman"                                                 
                                                
                      <[EMAIL PROTECTED]        To:       "Struts Users Mailing List" 
<[EMAIL PROTECTED]>                  
                      com>                     cc:                                     
                                                
                                               Subject:  Re: Indexed Properties        
                                                
                      07/28/2003 08:44                                                 
                                                
                      PM                                                               
                                                
                      Please respond to                                                
                                                
                      "Struts Users                                                    
                                                
                      Mailing List"                                                    
                                                
                                                                                       
                                                
                                                                                       
                                                




Yes, I currently have two independent String arrays for blockName and
blockType. Putting them, and all the other block related properties, is
what
seems to be the right thing to do! So you have confirmed.

here is what i have understood from your text:

1) my form would have "blocks" property that would be a collection of Block
beans
2) iterating each block in the blocks collection i can sure display each
block with "indexed=true" directive for text boxes and dropdowns.
3) now for the submission part i'd need to have setBlockType(int, string)
and getBlockType(int) and same for the rest of properties. The name of
property in the Block Form and name of the property in the Block Bean must
match.
4) and it should work?

I've had my head stuck in my computer whole day today and i'm barely able
to
write this email :) Tommorrow morning i'd come back and confirm it by
running it. meanwhile I'd appreciate if you could confirm these 4 points
i've noted above!

Thankyou very much for your help. It really did help.

Regards,

ATTA


----- Original Message -----
From: "Nick" <[EMAIL PROTECTED]>
To: "'Struts Users Mailing List'" <[EMAIL PROTECTED]>
Sent: Monday, July 28, 2003 5:08 PM
Subject: RE: Indexed Properties


> Hi Atta,
>
> No problem with the assistance.  Just hope that I can be helpful :-)  In
> the cases where I use indexed properties, the property is part of a
> larger object.  It sounds to me like you have two arrays in your form
> class: one for blockName and one for blockType.  I would suggest
> creating a bean with the two properties, and then have a collection of
> those objects in your form.
>
> Building on my previous example, you'd have something like this:
>  <logic:iterate name="blocks" id="oneBlock"
>          type="com.myco.beans.Block">
>      <td>
>        <html:text name="oneBlock" property="blockName" indexed ="true"/>
>      </td>
>      <td>
>        <html:select name="oneBlock" property="blockType"
>                     indexed="true" size="1">
>           <html:options name="myForm" property="blockTypes"/>
>        </html:select.
>      </td>
>  </logic:iterate>
>
> This example assumes your collection of blockTypes is part of your form,
> but it could be a collection that was in request/session/application
> scope.  You would create form entries for the collection like you
> implemented in our previous emails.
>
> I have almost this exact code in a few places and it works well.
>
> Hope this helps.
> Nick
>
> -----Original Message-----
> From: atta-ur rehman [mailto:[EMAIL PROTECTED]
> Sent: Monday, July 28, 2003 3:37 PM
> To: Struts Users Mailing List
> Subject: Re: Indexed Properties
>
> Thanks, for the reply.
>
> Okay, here is the background. I'm trying to learn the user of Indexed
> Properties. Why I'm doing that? Well, I have a form that lists, let's
> say
> for the sake of simplicity, Block Name and Block Type columns. Block
> Name is
> a readonly text field while the Block Type is a dropdown list box with a
> set
> of reference values  coming from the database. User can have n blocks on
> the
> page and he can change the block type of any block on the page. user
> cannot
> define a new block on this page.
>
> In my form I've got String[] getter/setters for blockName and blockType
> properties. In my action, I set both these arrays reading from the
> database.
> Block Names show allright, but the block type dropdown, that is using
> html:select tag, shows same type for all the blocks irrespective of the
> type
> of the block read from database.
>
> Now a few days back i asked a question on this forum regarding how to
> have
> my dropdowns display the right block type as set in the blockType
> String[]
> property of the form. Someone, I think it was Wendy Smoak, and i've seen
> quite a lot of helpful mails from him, mentioned that Indexed Properties
> might be the way go. Althogh, he also mentioned that he hasn't used
> them.
>
> I solved the problem by using "value" property of html:select tag. the
> doc
> says that "value" property denotes the value of the listbox that would
> be
> used to select an item in the list. so far so good.
>
> now the kind of guy i'm, i thought why not try it thrue index properties
> and
> learn something new ;) so i set out to learn indexed properties. read
> some
> articles and still i'm not sure what i'm missing.
>
> Hope this gives you the background and thanks once more for taking some
> out
> to hlep me.
>
> ATTA
>
> ----- Original Message -----
> From: "Nicholas L Mohler" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Monday, July 28, 2003 1:09 PM
> Subject: Re: Indexed Properties
>
>
> >
> >
> >
> >
> >
> > Atta,
> >
> > The complaint you are getting is because the property "fruit" is not a
> > property of the "oneF" bean.  That the oneF object is not a bean with
> > properties will give you problems.  Depending on your goal, you need
> to do
> > something different.  What are you trying to do?
> >
> > I'm off work in a minute, but I'll check messages at home later this
> > evening and see if I can help at all.
> > Nick
> >
> >
> >
> >
> >                       "atta-ur rehman"
> >                       <[EMAIL PROTECTED]        To:       "Struts Users
> Mailing List" <[EMAIL PROTECTED]>
> >                       com>                     cc:
> >                                                Subject:  Re: Indexed
> Properties
> >                       07/28/2003 03:44
> >                       PM
> >                       Please respond to
> >                       "Struts Users
> >                       Mailing List"
> >
> >
> >
> >
> >
> >
> > Thanks very much Nick! It was indeed helpful. I was missing
> getter/setter
> > for individual list items!
> >
> > now my form has following methods:
> > private String[] fruit = {"Apple", "Orange", "Banana"};
> >
> > public List getFruits() {
> >
> > return Arrays.asList(this.fruit);
> >
> > }
> >
> > public void setFruits(List l) {
> >
> > this.fruit = (String[]) l.toArray();
> >
> > }
> >
> >
> > public String getFruit(int index) {
> >
> > if (this.fruit == null) return "null";
> >
> > return this.fruit[index];
> >
> > }
> >
> > public void setFruit(int index, String f) {
> >
> > this.fruit[index] = f;
> >
> > }
> >
> > my JSP has following has this html:iterator:
> >
> > <logic:iterate name="theForm" property="fruits" id="oneF"
> > type="java.lang.String" >
> >    <tr>
> >     <td align="center">
> >      hi!
> >     </td>
> >     <td>
> >      <html:text property="fruit" name="oneF" indexed="true" />
> >     </td>
> >    </tr>
> >   </logic:iterate>
> >
> > and exception i get is this:
> >
> > javax.servlet.jsp.JspException: No getter method for property fruit of
> bean
> > oneF
> >              at
> > org.apache.struts.util.RequestUtils.lookup(RequestUtils.java:968)
> >
> >
> > i think it has to do with the fact that my individual fruit is a
> string
> > object rather than being a bean in itself if some getter method(s)?
> >
> > can you see what's going wrong!
> >
> > Thanks again.
> >
> > ATTA
> >
> > ----- Original Message -----
> > From: "Nicholas L Mohler" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Monday, July 28, 2003 11:58 AM
> > Subject: Re: Indexed Properties
> >
> >
> > >
> > >
> > >
> > >
> > >
> > > Atta,
> > >
> > > You can use indexed properties in your ActionForm class.  The key is
> > having
> > > all of the correct methods in your form class.
> > >
> > > 1)  Getter and setter:  You need a get/Set method for the collection
> that
> > > you refer to in your jsp.  for example:
> > > public Collection getLocations()
> > > public void setLocations(Collection locs)
> > >
> > > 2) Getter and setter for one instance in the collection.  The name
> that
> > you
> > > use must match the name you define in your jsp as a single instance
> from
> > > the collection (specified as the id).  For example:
> > >     <logic:iterate name="locations" id="oneLocation"
> > >             type="com.myco.toolkits.beans.Location">
> > >         <td>
> > >             <html:text name="oneLocation" property="locationName"
> indexed
> > > ="true"/>
> > >         </td>
> > >         <td>
> > >             <html:text name="oneLocation" property="locationAddress"
> > > indexed="true"/>
> > >         </td>
> > >     </logic:iterate>
> > >
> > > Your form should in this case have the following get/set methods:
> > > public com.myco.toolkits.beans.Location getOneLocation(int index)
> > > public void setOneLocation(int index,
> com.myco.toolkits.beans.Location
> > > oneLocation)
> > >
> > > Your code may never use either of the "oneLocation" methods, but
> they
> are
> > > important for Struts.  When your page is submitted, your two indexed
> > > properties will be submitted as oneLocation[ix].locationName &
> > > oneLocation[ix].locationAddress where ix is the index of the row
> (0-10
> > for
> > > example).  As Struts proceses the indexed items, Struts will use the
> > > "getOneLocation" method to get the Collection instance for the
> provided
> > > index.  This method must resize the collection as needed and then
> return
> > > the object for the provided index.  For example, if your collection
> has
> > no
> > > objects and the getter receives an index of 2, the method should
> load
> the
> > > first three (0, 1, 2) collection locations with an initialized
> object
> and
> > > return the third object.  Struts will then populate the appropriate
> > > property in that object.
> > >
> > > As an aside, I tend to use the ArrayList object as my collection
> type
> > when
> > > working with indexed properties, but I know that the Vector works
> equally
> > > well.  A simple array will work fine, but the logic to expand the
> size
> is
> > a
> > > little more involved.
> > >
> > > Let me know if this helps.
> > > Nick
> > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > 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]
>
>
>
> ---------------------------------------------------------------------
> 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