Reading query string inside the Flex Portlet

I made some changes in the Getting Query String of portal URL from inside the portlet code to use Flex on the client side. Now Flex is used for UI on the client side. You can download the sample code for portlet from here

The Portlet code remains the same, except one change, now i am forwarding control to query.jsp which is including Flex object on page using code like this

<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" session="false"%>
<%@taglib uri="" prefix="portlet"%>
<portlet:defineObjects />
<script type="text/javascript">

function getQueryString(){
console.log("Returning getQueryString");
return "<%=renderRequest.getAttribute("queryString")%>";

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="HelloWorld" width="500px" height="500px"
<param name="movie"
+ "/FlashQueryString.swf")%>' />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="sameDomain" />
<embed src="<%=renderResponse.encodeURL(renderRequest.getContextPath() + "/FlashQueryString.swf")%>"
quality="high" bgcolor="#869ca7" width="500px" height="500px"
name="HelloWorld" align="middle" play="true" loop="false"
quality="high" allowScriptAccess="sameDomain"
</embed> </object>

Also i have getQueryString function that returns the query string set by the Portlet code as request attribute.

My Flex code is very simple

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx=""
xmlns:mx="library://" minWidth="955"
minHeight="600" creationComplete="init()">
public function init():void{
var queryString ="getQueryString");
queryStringText.text = queryString;

<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:Panel x="5" y="10" width="284" height="172" title="Query String Demo">
<s:TextArea x="10" y="44" width="220" height="54" id="queryStringText" />
<s:Label x="10" y="10" text="Query String" width="167" height="30"/>

In the creationComplete() method of the Flex code i am calling getQueryString JavaScript method and setting value returned by it inside the text area for display

1 comment:

Anonymous said...

Very good example, it works fine, but one note, when the URL contains myportal, all the parameters vanish and become invisible for the request, do you faced this before ?