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]

Reply via email to