struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andy Noble" <andy.no...@data-workshop.com>
Subject Re: Design question - option lists populated from db
Date Tue, 11 Dec 2001 16:33:41 GMT
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 <rparker@bstonetech.com>
To: Struts Users Mailing List <struts-user@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 <rparker@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:
> > <mailto:struts-user-unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail:
> > <mailto:struts-user-help@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:
> <mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:struts-user-help@jakarta.apache.org>
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message