Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
A great example is there at: http://www.keyboardmonkey.com/StrutMonkey/MonkeyStruts_v2.jsp I have also implemented Show All and Hide All using the same technique. Works sweet. Affan - Original Message - From: Martin Cooper [EMAIL PROTECTED] To: Tag Libraries Users List [EMAIL PROTECTED] Sent: Saturday, December 21, 2002 4:55 AM Subject: RE: [JSTL] Help hiding/showing sections on JSP (w/ cookie?) On Fri, 20 Dec 2002, Wendy Smoak wrote: I've heard tell of folks serializing things such as this. If you're not in a distributed environment (or you somehow manage to have a shared directory available to all nodes of the cluser) you could probably do the same. Doing something along these lines would not only reduce the load on the DB, but enable the user the priviledge of having the same settings on every machine they visited the site from. You guys are full of ideas! I went with a boring old boolean[] that gets filled up like so: boolean[] profileSections = new boolean[ cookieValue.length ]; for (int i = 0; i cookieValue.length ; i++ ) { profileSections[i] = (cookieValue[i] == 'Y' ? true : false ); } and then stuck in the request: request.setAttribute( profileSections , profileSections ); The JSP code then checks to see if it should display a particular section: c:if test=${profileSections[0]} table.../table /c:if The bean with well-named methods is a much better idea, but this was easy enough without adding another class. I really wanted to stay out of the database for this part. You could use a DynaBean to avoid writing code for the JavaBean itself... -- Martin Cooper Thanks! I really couldn't find the right place to ask about this, so I appreciate your help even though it isn't strictly on topic. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management -- 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]
RE: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
I've heard tell of folks serializing things such as this. If you're not in a distributed environment (or you somehow manage to have a shared directory available to all nodes of the cluser) you could probably do the same. Doing something along these lines would not only reduce the load on the DB, but enable the user the priviledge of having the same settings on every machine they visited the site from. You guys are full of ideas! I went with a boring old boolean[] that gets filled up like so: boolean[] profileSections = new boolean[ cookieValue.length ]; for (int i = 0; i cookieValue.length ; i++ ) { profileSections[i] = (cookieValue[i] == 'Y' ? true : false ); } and then stuck in the request: request.setAttribute( profileSections , profileSections ); The JSP code then checks to see if it should display a particular section: c:if test=${profileSections[0]} table.../table /c:if The bean with well-named methods is a much better idea, but this was easy enough without adding another class. I really wanted to stay out of the database for this part. Thanks! I really couldn't find the right place to ask about this, so I appreciate your help even though it isn't strictly on topic. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management
RE: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
On Fri, 20 Dec 2002, Wendy Smoak wrote: I've heard tell of folks serializing things such as this. If you're not in a distributed environment (or you somehow manage to have a shared directory available to all nodes of the cluser) you could probably do the same. Doing something along these lines would not only reduce the load on the DB, but enable the user the priviledge of having the same settings on every machine they visited the site from. You guys are full of ideas! I went with a boring old boolean[] that gets filled up like so: boolean[] profileSections = new boolean[ cookieValue.length ]; for (int i = 0; i cookieValue.length ; i++ ) { profileSections[i] = (cookieValue[i] == 'Y' ? true : false ); } and then stuck in the request: request.setAttribute( profileSections , profileSections ); The JSP code then checks to see if it should display a particular section: c:if test=${profileSections[0]} table.../table /c:if The bean with well-named methods is a much better idea, but this was easy enough without adding another class. I really wanted to stay out of the database for this part. You could use a DynaBean to avoid writing code for the JavaBean itself... -- Martin Cooper Thanks! I really couldn't find the right place to ask about this, so I appreciate your help even though it isn't strictly on topic. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
[JSTL] Help hiding/showing sections on JSP (w/ cookie?)
I have a JSP with several sections, each of which needs to be hidden or shown based on user preference. I believe I've gotten the code done to toggle the on/off value of each section and to set a persistent cookie for the user in the form of: profile_sections = YYYNNNYYYNYNYNYYNN Now I'm working on the JSP code which will show (or not) each section as required. I don't know what the best way to do this would be. Do I add attributes to the request and then use x:if select={$showAddress} tabletrtdstuff/td/tr/table /x:if Or can I get at the cookie with JSTL? (And pick out a specific position of it??) The setting of the cookie is done in a Struts Action, so I've got Struts (and Struts-EL) tags available if one of those would be easier to use. Bear with me, it's my first cookie. :) If you have a suggestion for a different way to do this, I'm all ears. -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management
Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
On Thu, 19 Dec 2002, Wendy Smoak wrote: x:if select={$showAddress} tabletrtdstuff/td/tr/table /x:if Or can I get at the cookie with JSTL? (And pick out a specific position of it??) The setting of the cookie is done in a Struts Action, so I've got Struts (and Struts-EL) tags available if one of those would be easier to use. You can indeed read the cookie with expressions like ${cookie.key} in most cases, but you won't be able to get at a character position easily in the cookie -- at least not under JSTL 1.0. However, if you delimit the cookie's value with commas (e.g., Y,N,N,Y,...), you could in principle loop over the cookie's components with c:forEach and set different variables depending on what each individual value equals. The rough form of this solution looks like c:forEach items=${cookie.foo} var=e varStatus=c c:if test=${e == 'Y'} c:set target=${myMap} property=boolean${c.count} value=${true} / /c:if /c:forEach -- Shawn Bayern JSTL in Action http://www.manning.com/bayern -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
Shawn Bayern wrote: On Thu, 19 Dec 2002, Wendy Smoak wrote: x:if select={$showAddress} tabletrtdstuff/td/tr/table /x:if Or can I get at the cookie with JSTL? (And pick out a specific position of it??) The setting of the cookie is done in a Struts Action, so I've got Struts (and Struts-EL) tags available if one of those would be easier to use. You can indeed read the cookie with expressions like ${cookie.key} in most cases, but you won't be able to get at a character position easily in the cookie -- at least not under JSTL 1.0. However, if you delimit the cookie's value with commas (e.g., Y,N,N,Y,...), you could in principle loop over the cookie's components with c:forEach and set different variables depending on what each individual value equals. The rough form of this solution looks like c:forEach items=${cookie.foo} var=e varStatus=c c:if test=${e == 'Y'} c:set target=${myMap} property=boolean${c.count} value=${true} / /c:if /c:forEach Glass houses, stones, and all, but I think it's a yicky solution, far too dependent on nothing ever changing :) If I were doing it I'd explore other options (storing user prefs in a db indexed by a cookie value, for instance) and work off of that. Having position-dependent values seems an invitation to fragility. If you're dead-set on positional keys, maybe just using an integer and doing bit compares (I don't know how/if that works under JSTL, but it's a trivial custom tag) or something... Or just use a custom tag for the YNYNYYNN method, I suppose. Obviously the db (or similar) solution is more robust and mutable. Just my $0.02, sorry :) Dave -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
Glass houses, stones, and all, but I think it's a yicky solution, far too dependent on nothing ever changing :) If I were doing it I'd explore other options (storing user prefs in a db indexed by a cookie value, for instance) and work off of that. Having position-dependent values seems an invitation to fragility. I'm currently storing preferences in a database, but I wanted to move to cookies to avoid the overhead of the database connection. This isn't life or death-- just a convenience to remember what they were looking at last time they used the same computer and browser. If you're dead-set on positional keys, maybe just using an integer and doing bit compares (I don't know how/if that works under JSTL, but it's a trivial custom tag) or something... Or just use a custom tag for the YNYNYYNN method, I suppose. Obviously the db (or similar) solution is more robust and mutable. I'm not dead set on positional keys; that's just what came to mind to store as the cookie. In the Struts action, before it goes to the JSP, I can turn that cookie into anything-- a Map? An array of booleans?? What would be easy to deal with in either JSTL or Struts tags? That's what I came here to ask, really. I don't think reading the cookie with JSTL is the best solution necesarily, I just wondered if it was possible. Thanks! -- Wendy Smoak Applications Systems Analyst, Sr. Arizona State University PA Information Resources Management
Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
Shawn Bayern wrote: Oh, I definitely agree. Personally, I might just set multiple cookies, unless there were more than perhaps a dozen of them. That was my first thought too, but as I choose to confirm every cookie I get I discourage people from using them ;) Dave -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
Oh, I definitely agree. Personally, I might just set multiple cookies, unless there were more than perhaps a dozen of them. Unfortunately, there are already a dozen, and although we resist adding more sections to that page, I have a handful of requests, one or two of which will probably make it. I thought that was too many to set individual cookies. :( So I'd like to set one cookie, the format of which is open to suggestion, read it in a Struts Action, do whatever with the value, and then use some JSTL tags to decide whether or not to display a given section. Having never done anything of the sort before, either 0010001000 or YYYNNNYYNYNY came to mind. (And an evil coworker suggested turning the first into a decimal number before setting the cookie.) -- Wendy Smoak
Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
So I'd like to set one cookie, the format of which is open to suggestion, read it in a Struts Action, do whatever with the value, and then use some JSTL tags to decide whether or not to display a given section. Having never done anything of the sort before, either 0010001000 or YYYNNNYYNYNY came to mind. (And an evil coworker suggested turning the first into a decimal number before setting the cookie.) How about creating yourself a Javabean with a bunch of well-named boolean properties? In your Struts Action, read the flag data from the database, create and populate the bean, and put the bean in session scope to be accessed using the JSTL EL syntax. Brian -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: [JSTL] Help hiding/showing sections on JSP (w/ cookie?)
I've heard tell of folks serializing things such as this. If you're not in a distributed environment (or you somehow manage to have a shared directory available to all nodes of the cluser) you could probably do the same. Just either serialize them through the typical means or by using one of the new XML strategies. You could then implement a proxy for getting settings belonging to a given user which could easily be accessed via the JSTL. Doing something along these lines would not only reduce the load on the DB, but enable the user the priviledge of having the same settings on every machine they visited the site from. Wendy Smoak wrote: Oh, I definitely agree. Personally, I might just set multiple cookies, unless there were more than perhaps a dozen of them. Unfortunately, there are already a dozen, and although we resist adding more sections to that page, I have a handful of requests, one or two of which will probably make it. I thought that was too many to set individual cookies. :( So I'd like to set one cookie, the format of which is open to suggestion, read it in a Struts Action, do whatever with the value, and then use some JSTL tags to decide whether or not to display a given section. Having never done anything of the sort before, either 0010001000 or YYYNNNYYNYNY came to mind. (And an evil coworker suggested turning the first into a decimal number before setting the cookie.) -- Eddie Bush -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]