You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rob Parker <rp...@bstonetech.com> on 2001/12/11 15:49:03 UTC

Design question - option lists populated from db

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Design question - option lists populated from db

Posted by Andy Noble <an...@data-workshop.com>.
Rob,

When I looked into this, I realised that the problem you describe would
occur. Given that it occurs, and the list goes out of scope, you've got to
either requery the database or store the initial results in the session. I
decided to store user specific results in the session - but I'm building a
request-based app and hate putting data in the session.

I was considering giving session scoped attributes a limited lifetime (don't
know how yet exactly), where any session scoped attribute over 5 mins old
gets cleared out. I guess I may need to write a thread that scans session
scoped attributes and dereferences them, in a similar way to garbage
collection.

I've written a little LookupManager which stores application wide lists in
application scope and only retrieves the data from the database if its not
been previously retrieved, so I guess this could be extended to somehow
manage session scoped lists also.

I'll be watching responses to your question for more ideas.

Andy


----- Original Message -----
From: Rob Parker <rp...@bstonetech.com>
To: Struts Users Mailing List <st...@jakarta.apache.org>
Sent: Tuesday, December 11, 2001 3:44 PM
Subject: RE: Design question - option lists populated from db


> 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:keithbaconstruts@yahoo.com]
> 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 <rp...@bstonetech.com> 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:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
> __________________________________________________
> 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:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


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


RE: Design question - option lists populated from db

Posted by Rob Parker <rp...@bstonetech.com>.
That is exactly what I needed! Thanks,

Rob

-----Original Message-----
From: Will Jaynes [mailto:wjaynes@mediaone.net]
Sent: Tuesday, December 11, 2001 9:28 AM
To: Struts Users Mailing List
Subject: Re: Design question - option lists populated from db


Or, don't do the automatic validation.  Set validate='false' in the struts
config and then call the validate method explicitly from your action. If it
fails you still have the opportunity to fill the dropdown box and forward
back
to the jsp.

Will

----- Original Message -----
From: "Keith Bacon" <ke...@yahoo.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, December 11, 2001 11:32 AM
Subject: RE: Design question - option lists populated from db


> Hi Rob,
> Ah yes - my system is very simple. I'm not an advanced
> user - as a 'simpleton' I like to have all the
> validation in my business logic & never replicated
> elsewhere (but I can see the case for javascript
> validation in the browser, especially if genrated
> automatically).
>
> Putting stuff in the session keeps it but I hate that.
> Otherwise your form validate method has to add the
> collection to the request if it returns a validation
> error (yuk, yuk!).
>
> Or can you use <bean:define in your jsp to get the
> collection directly from your data supplying classes?
> Keith.
>
>
> --- Rob Parker <rp...@bstonetech.com> wrote:
> > 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:keithbaconstruts@yahoo.com]
> > 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 <rp...@bstonetech.com> 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:
> > >
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >
> >
> >
> > __________________________________________________
> > 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:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> === message truncated ===
>
>
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


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



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


Re: Design question - option lists populated from db

Posted by Will Jaynes <wj...@mediaone.net>.
Or, don't do the automatic validation.  Set validate='false' in the struts
config and then call the validate method explicitly from your action. If it
fails you still have the opportunity to fill the dropdown box and forward back
to the jsp.

Will

----- Original Message -----
From: "Keith Bacon" <ke...@yahoo.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, December 11, 2001 11:32 AM
Subject: RE: Design question - option lists populated from db


> Hi Rob,
> Ah yes - my system is very simple. I'm not an advanced
> user - as a 'simpleton' I like to have all the
> validation in my business logic & never replicated
> elsewhere (but I can see the case for javascript
> validation in the browser, especially if genrated
> automatically).
>
> Putting stuff in the session keeps it but I hate that.
> Otherwise your form validate method has to add the
> collection to the request if it returns a validation
> error (yuk, yuk!).
>
> Or can you use <bean:define in your jsp to get the
> collection directly from your data supplying classes?
> Keith.
>
>
> --- Rob Parker <rp...@bstonetech.com> wrote:
> > 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:keithbaconstruts@yahoo.com]
> > 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 <rp...@bstonetech.com> 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:
> > >
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >
> >
> >
> > __________________________________________________
> > 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:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> === message truncated ===
>
>
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>


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


RE: Design question - option lists populated from db

Posted by Keith Bacon <ke...@yahoo.com>.
Hi Rob,
Ah yes - my system is very simple. I'm not an advanced
user - as a 'simpleton' I like to have all the
validation in my business logic & never replicated
elsewhere (but I can see the case for javascript
validation in the browser, especially if genrated
automatically).

Putting stuff in the session keeps it but I hate that.
Otherwise your form validate method has to add the
collection to the request if it returns a validation
error (yuk, yuk!).

Or can you use <bean:define in your jsp to get the
collection directly from your data supplying classes?
Keith.


--- Rob Parker <rp...@bstonetech.com> wrote:
> 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:keithbaconstruts@yahoo.com]
> 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 <rp...@bstonetech.com> 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:
> >
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
> 
> 
> __________________________________________________
> 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:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

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


RE: Design question - option lists populated from db

Posted by Rob Parker <rp...@bstonetech.com>.
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:keithbaconstruts@yahoo.com]
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 <rp...@bstonetech.com> 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:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>


__________________________________________________
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:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



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


Re: Design question - option lists populated from db

Posted by Keith Bacon <ke...@yahoo.com>.
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 <rp...@bstonetech.com> 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:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


__________________________________________________
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>