4 Replies Latest reply on Mar 30, 2011 9:41 AM by aaalto

    query string in freemarker Widget template


      ...can anyone please please tell me how to access the query string in either my BaseWidget class or freemarker template?  There is a StrutsRequestWrapper object but it doesn't contain any of the query string values.  Do Widgets have access to the query string or request.getParameter?


      Thanks in advance!



        • Re: query string in freemarker Widget template
          Ryan Rutan Guru

          Try the Struts ActionContext, it should work, such as this:



          As a side note, I'm not sure I'd rely on Request Parameters for your Widget.  If you are trying to make a multi-stage widget...you'd be better off making a DWR component that can refresh your widget's context.  Granted that's a bit more work...just thought I'd mention.  Good luck! =)

            • Re: query string in freemarker Widget template

              Thank you!  Unfortunately this does not work - using the following URL:




              ...the following code in my BaseWidget class:


                  String test = (String)ActionContext.getContext().getParameters().get("test");







              ...and the ActionContext is undefined within the freemarker template.  I'm saddened by how seemingly difficult this has become, but I guess I have no choice but look into the DWR approach.  I'm brand new to DWR - any tips as to where I should get started?


              Thanks again!



                • Re: query string in freemarker Widget template
                  Ryan Rutan Guru

                  Apparently the Widget is being rendered in another thread ... otherwise this should have worked.  I have never tried this because I have never had the need to do something like this.  Instead of my sending you down the DWR path blindly (which is not necessarily easy)...could you explain what you are trying to do, and perhaps that will trigger some different ideas?

                    • Re: query string in freemarker Widget template

                      I think I figured out a way to make things work.  In my case, I could use javascript within widget template to get the query string data as I need this data after template processing, like so:


                      <#assign idPrefix = StringUtils.randomString(6) />

                      <script type="text/javascript">

                      var qs=location.search.substring(1,location.search.length);

                      var container = document.getElementById('myWidget${idPrefix}');

                      container.innerHTML = '<input type="hidden" name="queryString" value="'+qs+'"/>';


                      <div id="myWidget${idPrefix}"></div>


                      Presuming this is within the context of a form, the "queryString" data will be passed upon form submission.  (I also chose not use jQuery calls as I wanted to ensure this could be stand alone.)


                      I had a strange problem that if the <script> tag was first in the template, it wouldn't render properly.  ...not sure why, but I just remark on this for other's benefit that I had to play with this.


                      In any event, thanks Ryan for the help!