Thanks - I am doing almost exactly the same thing, but I am running into a
problem. If form level validation fails, the action is not called and the
lists go out of scope in the jsp page. Are you performing validation in the
form? How do you get around this problem? Thanks for taking the time to put
this together,

Rob

-----Original Message-----
From: Keith Bacon [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 11, 2001 7:34 AM
To: Struts Users Mailing List
Subject: Re: Design question - option lists populated from db


Rob,
Hope this helps - it's from a 'working' system. Ask
for more explanations - or better still beat your way
thru the struts docs. No escaping it takes time to get
your head around this stuff - but it's brill once you
get the hang of it!
Keith.
PS - My code hasnon-standard msg logging & the text in
the select ox isn't internationalised (yet!).
======================
1 - In the JSP.
=====================
                <html:select name="linkListForm"
                                property="selectedReviewDisplayTypeOption" >
                        <html:options
collection="reviewDisplayTypeOptions"
                                property="option"
                                labelProperty="label" />
                </html:select>&nbsp;
===================================================
2 - In your action class. Do this every time you
forward to the jsp taht displays the select/options.
In your case you need to pass parms to this method, my
example displays the same list for all users.
===================================================
request.setAttribute("reviewDisplayTypeOptions",
ReviewDisplayTypeOption.getDisplayTypeOptions());
        }
============================================
3 - Instance of this class gets added to the request.
This class also has the utility method called in 2)
above. In your case that method should be in a class
representing the data - or left here & changed to get
the data from the database (my example has the data
hard coded).
=========================================
package biff1;

        import java.util.ArrayList;

          /**
          * The option object
          * plus static methods to return the array
list of the real data.
          * dodgy having list underneath the single
list item object -qq?
          */
public final class ReviewDisplayTypeOption  extends
Object {
        private final static String THIS_NAME =
"ReviewDisplayTypeOption";

        private String dtOption = null;
        private String dtLabel  = null;

        ReviewDisplayTypeOption(String  dtOption, String
dtLabel) {
                this.dtOption = dtOption;
                this.dtLabel  = dtLabel;
        }

        public String getOption() {
                return dtOption;
        }
        // needed qq?
        public void setOption(String dtOption) {
                this.dtOption = dtOption;
        }
        public String getLabel() {
                return dtLabel;
        }
        // needed qq?
        public void setLabel(String dtLabel) {
                this.dtLabel = dtLabel;
        }

        static private void dbmi(String message) {
                ZUtils.writeLog(THIS_NAME, ZUtils.INFO_LEVEL,
message);
        }
        static private void dbmd(String message) {
                ZUtils.writeLog(THIS_NAME, ZUtils.DEBUG_LEVEL,
message);
        }
        static private void dbmw(String message) {
                ZUtils.writeLog(THIS_NAME, ZUtils.WARNING_LEVEL,
message);
        }

        static private ArrayList ReviewDisplayTypeOptions =
null;
        static public ArrayList getReviewDisplayTypeOptions()
{
                if (ReviewDisplayTypeOptions == null) {
                        ReviewDisplayTypeOptions = new ArrayList(12);
                        ReviewDisplayTypeOptions.add(new
ReviewDisplayTypeOption("excludeReviews", "Exclude
Reviews"));
                        ReviewDisplayTypeOptions.add(new
ReviewDisplayTypeOption("shortReviews"  , "Short
Reviews"));
                        ReviewDisplayTypeOptions.add(new
ReviewDisplayTypeOption("fullReviews"   , "Full
Reviews"));
                }
                return ReviewDisplayTypeOptions;
        }
        static public String getDefaultOption() {
                String sss =
((ReviewDisplayTypeOption)getReviewDisplayTypeOptions().get(0)).getOption();
                dbmd("getDefaultOption: returning:"+ sss);
                return sss;
        }
} // end Class ReviewDisplayTypeOption
=============================


--- Rob Parker <[EMAIL PROTECTED]> wrote:
> I need to create some <select> option lists that are
> populated from a
> database. The call to the database will pass in the
> current user's id to
> create customized option lists. Where is the best
> place to create these
> option lists? If I create the lists in the user
> form, how can I pass in the
> user id? How would I handle SQLExceptions in the
> user form? If I create the
> lists in the action, how can I avoid having them go
> out of scope when user
> form validation fails? (I do not want to add them to
> the session) Thanks in
> advance for any help - I am really stuck with this.
>
> Rob
>
>
> --
> To unsubscribe, e-mail:
> <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
> <mailto:[EMAIL PROTECTED]>
>


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com

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



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

Reply via email to