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="http://java.sun.com/portlet_2_0" prefix="portlet"%>
<portlet:defineObjects />
<script type="text/javascript">

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

</script>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="HelloWorld" width="500px" height="500px"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie"
value='<%=renderResponse.encodeURL(renderRequest.getContextPath()
+ "/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"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</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="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
minHeight="600" creationComplete="init()">
<fx:Script>
<![CDATA[
public function init():void{
if(ExternalInterface.available){
var queryString = ExternalInterface.call("getQueryString");
queryStringText.text = queryString;
}
}

]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<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"/>
</s:Panel>
</s:Application>


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

2 comments:

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 ?

Abhi said...

Thanks for info....
SEO Company in Bangalore