Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
getDefaultValue list and rptdesign
brian.lieb@noaa.gov
<p>All of our reports are accessed via the Birt Viewer and they have these two hidden, but required parameters:</p><p> </p><p>pUserName</p><p>pPassword</p><p> </p><p>Since the initial entry into the reports is a post from a web application, we can ensure that those two parameters are passed to the initial report. However, when we want to do a drill through to another report, we either need to pass those parameters as URL variables (via the hyperlink parameters screen) or, as I have done, set session variables to hold those values and then retrieve them as default values later. To do this, I have put this script in the parameter validate event:</p><div><pre class="_prettyXprint">importPackage( Packages.javax.servlet.http);var request = reportContext.getHttpServletRequest();var session = request.getSession();session.setAttribute("pUserName", params["pUserName"].value);true;</pre><p>This sets the session attribute pUserName to be the value of the pUserName parameter. So when drilling into another report, or even viewing another report later, I would like to not have to pass or ask for these parameters again, so in the getDefaultValueList event of the same parameter I have this code:</p><div><pre class="_prettyXprint">importPackage( Packages.javax.servlet.http);var request = reportContext.getHttpServletRequest();var session = request.getSession();session.getAttribute("pUserName");</pre></div><p>This sets the default value of the pUserName parameter to the value of whatever is in the session attribute of the same name.</p><p> </p><p>This works great when the report is running on Tomcat using the Birt Viewer.</p><p> </p><p>====</p><p>Now, here is my problem. Since the pUserName parameter is hidden and required (by design) and sessions don't really exist in the eclipse Birt designer, when I click 'View Report' from eclipse I always get an error indicating that pUserName isn't set.</p></div><p> </p><p>If I go into the report design, and Edit the Parameter, I can set its default value. However, this appears to be overridden by what is returned from the getDefaultValueList event.</p><p> </p><p>My question is this, is there some way in the getDefaultValueList event to check if the parameter default value was explicitly set in the report design before I set it to the value of the session attribute?</p>
Find more posts tagged with
Comments
kclark
<p>Why don't you set the default parameter value to some string like an md5 hash. Then in your getDefaultValueList() do something like</p><pre class="_prettyXprint">if(params["pUserName"] != "somestring") { // it's been changed}else{ // it hasn't been changed}</pre>
brian.lieb@noaa.gov
<p>I believe that I am misunderstanding what you are saying. So, I have made a brand new report that has a parameter called myParam that the report then displays in a dynamic text box.</p><p> </p><p>To see if I can access the value of the explicitly defined default value for myParam within the getDefaultValueList() event, I have done this in that event:</p><p> </p><div><pre class="_prettyXprint">var username;if (params == null) username = "no params";elsetry{ username = params["myParam"];}catch (e){ username = "Assigning to myParams threw an error. " + e.toString();}username;</pre></div><p>Even though myParams is explicitly set in the parameter dialog to be 'booyah', this code always prints:</p><p> </p><p>"Assigning to myParams threw an error. Report parameter"</p><p> </p><p>The same is true if I do this:</p><div><pre class="_prettyXprint">var username;if (params == null) username = "no params";elsetry{ username = params["myParam"].value;}catch (e){ username = "Assigning to myParams threw an error. " + e.toString();}username;</pre><p>So, when I tried the code you showed, I think that it was always throwing an exception.</p></div>