You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/06/09 19:37:20 UTC

Re[2]: best way to put index of collection in option(s) tag ?

On Sunday, June 9, 2002, 11:10:21 AM, Sandeep Takhar wrote:

ST> It seems to me that having the index is very similar to having a
ST> primary key.  So maybe what you add to the collection should be
ST> given a primary key which may just be the index into the
ST> collection.

    I'm not so sure it's really like a primary key, since it's only
    the index of place in the Collection the bean resides. (It
    obviously could vary when the sort changes).

    Also another issue is the Collection is populated in the business
    layer in the DAO, so does it really make sense for the bean to
    have a field for an index that 'might' get populated if it's used
    in a Collection? (I'm not saying it doesn't make sense, just
    thinking aloud ).

    [original post below:]

ST> --- Rick Reumann <ma...@reumann.net> wrote:

>> What is the best way to put the index value of a
>> collection in a
>> select options list? I'm currently doing this:
>> 
>> <html:select styleClass="field"
>> property="userTypeId">
>>   <logic:iterate id="element" name="userTypes"
>> indexId="index" >
>>     <html:option value="<%= index.toString() %>">
>>       <bean:write name="element"
>> property="displayName"/>
>>     </html:option>
>>   </logic:iterate>
>> </html:select>
>> 
>> I don't like the above since it requires the
>> scriplet. I suppose I
>> could give my form bean an indexId attribute so when
>> it's populated
>> into the collection I later could do:
>> 
>> <html:select styleClass="field"
>> property="userTypeId">
>>   <html:options collection="userTypes"
>>       property="indexId"
>> labelProperty="displayName"/>
>> </html:select>
>> 
>> The later seems cleaner in the presentation view but
>> for some reason
>> it doesn't sit right with me for a bean to have to
>> keep a field for
>> knowing what place it might hold in a Collection. I
>> take it I'd also
>> have to call setIndexId( i++ ) or something similar
>> whenever I add
>> these beans to the collection. Seems like that
>> shouldn't be something
>> a bean should have to worry about, but I'm probably
>> wrong:)
>> 
>> How do you guys handle this?
>> 
>> TIA
>> 
>> --
>> 
>> Rick
>> 
>> mailto:maillist@reumann.net
>> 
>> 

--

Rick

mailto:maillist@reumann.net

"If you go parachuting, and your parachute doesn't open, and you
friends are all watching you fall, I think a funny gag would be to
pretend you were swimming."
  -Jack Handey


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>