Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm Yeah. I've been trying to get the ID of the currently logged in user (extracted from the session) to display on a WebManager page, using the following snippet: [code] <% HttpSession session = request.getSession(true); String userData = (String) session.getAttribute("GX_user"); if (userData != null) { int start = userData.indexOf("<id>"); int end = userData.indexOf("</id>"); if (start != -1 && end != -1) { String userId = userData.substring(start, end); this.getServletContext().setAttribute("userid", userId); } } %> <c:if test="${not empty userid}"> User ID: ${userid} <% response.getOutputStream().print(userId); %> </c:if> <c:if test="${empty userid}"> No user ID set, are you logged in? </c:if> [/code] This works, BUT, once the user ID variable has been set, it won't change into something else again (tested in this case by logging out - the page still says the current user's ID is '3'). I'm pretty sure that this is due to the caching system - i.e. a page and the replacement fields aren't regenerated for each request. So the question is: How would I get the user ID to be regenerated and placed into the JSP's output properly each time? I've also tried the following: [code] response.getOutputStream().print(userId); [/code] but that (for some reason) results in an undetailed 500 error. For the record, errors without a proper reason are irritating. So, what's another way of doing this? I tried to look it up on Google, but I couldn't find anything, :/. Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2320 patricka Tough questions! While pondering the answer, my roommate stumbled upon the following bit of code in the wmpcommunityedition xslStyleSheet.jspf:<br /><br /></p><div class="code"><div class="codeContent"><pre>&lt;c:forEach var=&quot;presentation&quot; items=&quot;${website.presentations}&quot;&gt;<br /> &lt;c:if test=&quot;${presentation.scopes[0] == &apos;WebSite&apos; &amp;&amp;<br /> fn:startsWith(presentation.identifier,&apos;xslStyleSheetWCB&apos;)}&quot;&gt;<br /> &lt;wm:render presentationName=&quot;${presentation.identifier}&quot; /&gt;<br /> &lt;/c:if&gt;<br />&lt;/c:forEach&gt;</pre></div></div><p class="messageContent"><br /><br />A hook! <img src="/static/forum/icons/smiley_eek.gif"/><br /><br />This means that if you start the name of your presentation with &quot;xslStyleSheetWCB&quot; and give it scope &quot;WebSite&quot;, it will be picked up and rendered in the general stylesheet.<br /><br /><br />See, personalization is all about getting the expressions in the XSL stylesheet. This hook will allow you to create a presentation and have it embedded in the XSL stylesheet. E.g. like below:<br /><br /></p><div class="code"><div class="codeContent"><pre>&lt;!-- chtulhuLovesUserid.xml --&gt;<br />&lt;presentation&gt;<br /> &lt;name&gt;xslStyleSheetWCB Cthulhu Loves Userid&lt;/name&gt;<br /> &lt;display-name&gt;Cthulhu Loves Userid&lt;/display-name&gt;<br /> &lt;scope&gt;WebSite&lt;/scope&gt;<br />&lt;/presentation&gt;</pre></div></div><p class="messageContent"><br /><br />and<br /><br /></p><div class="code"><div class="codeContent"><pre>&lt;xsl:template match=&quot;wm-cthulhu-loves-userid&quot;&gt;<br /> &lt;xsl:value-of select=&quot;/root/system/user/userid&quot;/&gt;<br />&lt;/xsl:template&gt;</pre></div></div><p class="messageContent"><br /><br />And elsehwere you would put that tag to good use in your favorite .jspf.<br /><br />As for the second question: I don&apos;t think there is a better way to determine the userid, because your code will probably not be called at all because of caching. If you want to execute code and be sure of the userid, use personalization to determine it and use that id in either a server side include (SSI) or an AJAX call.<br /><br />Greetings,<br /><br />Patrick<br /> Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2305 Cthulhu Yeah, that looks like it&apos;ll do what I&apos;m looking for. Just a few more questions, bear with me ^^.<br /><br />* Is it possible to add this personalization through a WCB&apos;s code? You know, so the WCB will work out of the box.<br /><br />* Is there (again, in code) a neater way to get the current user&apos;s ID than to manually parse or extract the ID from the HttpSession? Can that xquery be executed on some API-available object to get the same results?<br /><br /><br />Edit: Yeah, that&apos;ll do the trick, =D. Thanks you guys. Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2302 patricka It just so happens that I was training this topic today! <img src="/static/forum/icons/smiley_grin.gif"/><br /><br />The document &quot;<a href="http://www.gxdeveloperweb.com/Software/Documentation.htm#GXD0019" rel="nofollow" target="_blank">Personalization Toolkit</a>&quot; is your friend. Also, take a peek at the <a href="http://wiki.gxdeveloperweb.com/confluence/display/GXDEV/XMLdebug" rel="nofollow" target="_blank">XMLdebug</a> info to find out the XPATH expression to the userid.<br /><br />In short: I&apos;m guessing that making a &quot;select&quot; expression for &quot;/root/system/user/userid&quot;, tagging it as &quot;wm-cthulhu-loves-userid&quot; and typing a tag &lt;wm-cthulhu-loves-userid/&gt; somewhere on the page would do the trick.<br /><br />Greetings,<br /><br />Patrick Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2301 Cthulhu I&apos;ll go give those personalization expressions a look at, thanks. And yeah, I guessed as much about the caching and JSP snippets, <img src="/static/forum/icons/smiley_grin.gif"/>. Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2300 martinvm Hi Cthulhu <br /><br />It is not recommended to use Java snippets in JSPs (as is stated in the Design API manual) because their behavior is unpredictable in environments with heavy caching. JSPs are only rendered again if the timestamp expires, which is not on every request.<br />If you need truly dynamic calls you have to use other methods such as personalization or filters or a combination of both. Displaying a (really) variable variable on an otherwise cached page http://www.gxdeveloperweb.com/Forums/Forum-JSP-Front-End-Development/test-delete-1.htm?pagenr=1#message2299 williamb While I was reading the upper half of your message I was thinking &quot;Would the cache allow this? As the page itself doesn&apos;t change, the JSP wouldn&apos;t be rendered again...&quot;. <br />Reading the rest of the question confirmed my thoughts: that is caching!<br /><br />Why not add a personalization expression here like &lt;wm-userid&gt; and use personalizations to render your data here?