Yeah, that's a very good point.  I would actually probably do it that way,
also.  I had written up a little tag that lets you pass an array ID and
value and it generates the option list for you, with the item with the
indicated value selected, but I don't have the code for that handy...

I think what it comes down to is, once you've got the basic functionality
built out, there are a LOT of ways to clean and streamline this sort of
code.  Getting the BeanUtils working with it makes the processing really
slick (although figuring out the syntax can be a bit of a nightmare!).  If
I can ever find my stupid sandbox app with this functionality in it, I'll
repost it.

[EMAIL PROTECTED] wrote:
> Just something I use...
>
> Rather than
>
> <option value="A"<c:if test="${item.code == 'A'}">
> selected</c:if>>A</option>
>
> I tend to use EL for the conditional to determine the selected item with
>
> <option value="A" ${item.code eq "A" ? " selected " : ""}>A</option>
>
> This way the < > 's all match up so if you're using any html designer it
> wont be effected.
>
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Rick
> Herrick
> Sent: Monday, October 02, 2006 9:00 PM
> To: displaytag-user@lists.sourceforge.net
> Subject: Re: [displaytag-user] Dropdown selection - displaytag 1.0
>
> Rick Herrick wrote:
>> Reg Sherwood wrote:
>>> I'm faced with an interesting problem - I am using displaytag 1.0
>>> (non
>>> el) combined with struts 1.2.9.  I have a table with a number of
>>> columns and rows; all columns are static display data except for the
>>> last which is a dropdown box where the user can modify a value
>>> associated to the given row (think of it as a status column).  What I
>>> want to know is if its possible on form submission to somehow figure
>>> for each row in the displaytag the currently selected value of the
>>> dropdown.  Anyone have suggestions?  All are welcomed.
>>
>> I do.  I'll post it up later.
>>
>> This is YAF (yet another FAQ :).
>
> OK, apologies for the delay.  On top of a sick daughter, a wife leaving
> town
> on a business trip, and a catastrophic hard drive failure... I've been
> kinda
> busy lately!
>
> So I'm gonna write up the Fred Flintstone method for handling drop-down
> lists in forms with displaytag.  I'll give you some pointers later on how
> to
> do this more elegantly.  Also, I'm writing this using Java 5/JSP 2.4
> in-line
> EL.  For older set-ups (JSP 2.3 and earlier) you'll have to use JSTL tags.
> This is a silly example, with a person's name and the ability to set a
> code
> for the person.
>
> First, set up a form with the displaytag table inside it:
>
> <form action="xxx">
>    <display:table name="items" uid="item">
>       <display:column property="name"/>
>       <display:column title="Code">
>          <select name="code_${item.id}">
>             <option value="A"<c:if test="${item.code == 'A'}">
> selected</c:if>>A</option>
>             <option value="B"<c:if test="${item.code == 'B'}">
> selected</c:if>>B</option>
>             <option value="C"<c:if test="${item.code == 'C'}">
> selected</c:if>>C</option>
>          </select>
>    </display:table>
>    <input type="submit"
> </form>
>
> So what will happen with this is that the list will be iterated, the name
> will be displayed, and for each item the code_XXXX drop-down list will be
> created.  The <c:if>s inside the option list will check each user to see
> what code is set for the user and add "selected" to the appropriate option
> in the list.
>
> Processing this as it's reposted is simply a matter of find all request
> parameters that begin with "code_".  Grab those, lop off the "code_" and
> that'll give you the item ID to which that selection applies.  Get the
> value
> of the list and set the code property on that item to whatever value you
> got.
>
> Like I said, this is the Fred Flintstone way of dealing with it.  You're
> out
> there munging strings together and parsing them out and it's fairly ugly.
> There are many ways to streamline this:
>
> * Take the options in your drop-down list from an enum or string array.
> You can then just do a <c:iterate> on that enum or array and collapse the
> code for the drop-down list.  This is especially useful when you might
> have
> a pretty large number of items in that list.
>
> * Use the BeanUtils library!  This is a big one, although it can be kinda
> hard to figure out.  Basically instead of doing "code_XXXX" and having to
> parse the request parameter names, you do something like "code[XXXX]" and
> objects will get magically referenced properly.  Somewhere I have a nice
> sandbox app that illustrates this, but I couldn't find it over the weekend
> (catastrophic hard drive failure, remember? :^( ).
>
> Drop a line to the list if you have any questions!
>
> --
> Rick Herrick
> [EMAIL PROTECTED]
>
> Proud member of the reality-based community
>
> Never try to discourage thinking for you are sure to succeed.--Bertrand
> Russell
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's
> Techsay panel and you'll get the chance to share your opinions on IT &
> business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> displaytag-user mailing list
> displaytag-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/displaytag-user
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.407 / Virus Database: 268.12.11/460 - Release Date:
> 01/10/2006
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.407 / Virus Database: 268.12.11/460 - Release Date:
> 01/10/2006
>
>
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> displaytag-user mailing list
> displaytag-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/displaytag-user
>


-- 
Rick Herrick
[EMAIL PROTECTED]

Proud member of the reality-based community

Never try to discourage thinking for you are sure to succeed.--Bertrand
Russell

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
displaytag-user mailing list
displaytag-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/displaytag-user

Reply via email to