Select to view content in your preferred language

How can i pass parameter from my custom mxml to flex viewer header widget

2123
15
Jump to solution
07-29-2014 01:10 AM
NadirHussain
Occasional Contributor II

Dear All/Robert Shilten

I want to pass one parameter from my custom mxml page to header widget of flex viewer.please help me in this matter,

Thanks to All.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Nadir,

  Sure I have a couple of sites setup to use a login page that is part of the Viewers source code. You can find the code for this here http://gis.calhouncounty.org/devsummit2012/devsumit2012.zip It just sets up states on the main index.html page and the initial state is the login stuff and it will not switch states until login is successful. The ASP.net web service included also has the ability based on login to define which main config.xml the user is to receive.

View solution in original post

0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   You would use widget communication. Widget Communication Explained‌ You will have to edit the Header Controller widget to listen for the data you are sending as well. If you provide more specifics than I can provide more detailed instructions.

0 Kudos
NadirHussain
Occasional Contributor II

Dear Robert

I have my custom mxml page.this page receive some parameter from database.from these parameter I decide current user.where this user is from admin group or normal group.from the value of the database  I send one value to header widget as according to the user group and visible and hide some options for the user.please help to sove this.i already use single ton pattern.but so for no success.Always get null value in header widget.

\thanks in advance

0 Kudos
NadirHussain
Occasional Contributor II

  -----Sender Custom Page------------------

xmlns:fx="http://ns.adobe.com/mxml/2009" ibrary://ns.adobe.com/flex/spark"

library://ns.adobe.com/flex/mx"Login Page" minWidth="955" minHeight="600" backgroundColor="#8099B2">

<s:layout>

<s:BasicLayout/>

</s:layout>

<fx:Declarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

<s:HTTPService id="UserService" url="http://localhost/mySirensData/Default.aspx" fault="httpFaultHandlerData(event)"  showBusyCursor="false" requestTimeout="300"  result="DataHandler(event)" resultFormat="xml" method="post" />

</fx:Declarations>

<fx:Script>

import com.esri.viewer.AppEvent;

import com.esri.viewer.BaseWidget;

import com.esri.viewer.IBaseWidget;

import mx.rpc.events.FaultEvent;

import mx.rpc.events.ResultEvent;

import mx.rpc.remoting.Operation;

import mx.rpc.xml.SimpleXMLDecoder;

import mx.rpc.xml.SimpleXMLEncoder;

import mx.utils.ArrayUtil;

import mx.utils.StringUtil;

[Bindable]

private var RAc:ArrayCollection;

[Bindable

public var params:Object ={};

private function httpFaultHandlerData(event:FaultEvent):void

{"There was a problem in sending","Error " + event.message.toString());}

private function DataHandler(event:ResultEvent):void

{

  var msArr:ArrayCollection = new ArrayCollection();

   var transferData:Object = {message:"UserGroup",Value:RAc[0]["Countchk"]};

    msArr.addItem(transferData);

   //Not visible in my custom page method of basewidget class .addSharedData( );

}

private function convertXmlToArrayCollection(file:String):ArrayCollection

{

var xml:XMLDocument = new XMLDocument(file);

var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();  

var data:Object = decoder.decodeXML( xml );  

var array:Array = ArrayUtil.toArray(data.parent.child);  

return new ArrayCollection(array) ;  

}

</fx:Script>

<mx:LinkButton id="NewUser" x="10" y="5" width="126" height="24" label="New User" color="#FF3322" fontFamily="New Times Roman" fontWeight="bold" fontSize="20" fontStyle="normal" visible="false" click="linkbutton1_clickHandler(event)"/>

<s:BorderContainer x="423" y="226" height="109" width="472"  borderColor="#FFFFFF"  backgroundColor="#8099B2" borderStyle="solid" borderWeight="2" >

<s:VGroup height="60" width="100%" >

<s:FormItem width="460" height="20" label="User Name:   " textAlign="left" color="#000000">

<s:TextInput id="txtUser" width="100%" color="#00000"/>

</s:FormItem>

<s:FormItem width="460" height="12" label="Password:      " textAlign="left" color="#000000">

<s:TextInput id="txtPass" top="0" width="100%" color="#00000" displayAsPassword="true"/>

</s:FormItem>

</s:VGroup>

<s:HGroup x="0" y="75" width="100%" height="25" horizontalAlign="center"  verticalAlign="justify" color="#00000">

<s:Button id="lblLogin" label="Login" x="100" click="lblLogin_clickHandler(event)"/>

<s:Button id="lblCancel" label="Cancel" x="100" />

</s:HGroup>

</s:BorderContainer>

</s:Application>

from remote service result received and this send to header widget.

----------Receiver Widget----------------------------------

xmlns:fx="http://ns.adobe.com/mxml/2009"

library://ns.adobe.com/flex/spark"

library://ns.adobe.com/flex/mx"

com.esri.viewer.*"

com.dougmccune.controls.*"

rtl"

100%" initialize="basewidget_initializeHandler(event)"

>


<fx:Script>


import com.esri.viewer.AppEvent;

import com.esri.viewer.TransferDataManager;

import com.esri.viewer.ViewerContainer;

function basewidget1_creationCompleteHandler(event:FlexEvent):void

{
//  I want to get parameter value in this function

  On this value I will decide show or hide the edit option for the user.

}

private function img_clickHandler(event:MouseEvent):void

{

if(event.currentTarget.id=="IdentifyBtn")

"Identify"));

else if(event.currentTarget.id=="layers")

"Layers"));

else if(event.currentTarget.id=="Edit")

{

var url:URLRequest = new URLRequest("EditPage.html");

var uv:URLVariables = new URLVariables();

"post";

"fred";

_blank");

else if(event.currentTarget.id=="drawingToolsBtn")

((Tools"));

</fx:Script>


<mx:Canvas id="myCanvas"  x="0" y="0" width="100%" backgroundColor="0x8099B2" height="150" borderColor="#FFFFFF">


<mx:Image id="imgbg" x="0" y="0" width="100%" height="80%" layoutDirection="ltr"   maintainAspectRatio="false" source="assets/images/headerLogo.png/>


<mx:Image id="layers" x="5" y="120" width="10%" height="20%" layoutDirection="rtl" toolTip="All Layers"   source="assets/images/02_Header.png" click="img_clickHandler(event)" />



<mx:Image id="IdentifyBtn" x="100" y="120" width="15%" height="20%" layoutDirection="rtl" toolTip="Identify"   source="assets/images/i_info.png" click="img_clickHandler(event)" />


<mx:Image id="SearchButtonByRegion" x="200" y="122" width="10%" height="20%" layoutDirection="rtl" toolTip="Search By Region"   source="assets/img/11.png" click="img_clickHandler(event)" />


<mx:Image id="SearchButtonByCity" x="290" y="122" width="10%" height="20%" layoutDirection="rtl" toolTip="Search By City"   source="assets/img/12.png" click="img_clickHandler(event)" />


<mx:Image id="Edit" x="400" y="122" width="10%" height="20%" layoutDirection="rtl" toolTip="Edit"   source="assets/images/i_draw.png" click="img_clickHandler(event)" />


<mx:Canvas>


please read the creation complete handler.i want to get value from custom page here and on this value I will decide to show/hide edit option to the user.

Thanks in advance.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

  The addSharedData function in the BaseWidget is just a simple function that dispatches an AppEvent. You can do that in your custom mxml yourself.

var data:Object =

     {

          key: key,

          collection: arrayCollection

     };

AppEvent.dispatch(AppEvent.DATA_PUBLISH, data);

0 Kudos
NadirHussain
Occasional Contributor II

dear robert,

i try it but cant succeed,see my sender and receiver function are below.please help i am stuck here from one week.

sender function.------------------

var url:URLRequest

var uv:URLVariables;

var msArr:ArrayCollection = new ArrayCollection();

var transferData:Object = {message:"UGroup",Value:"0"};

msArr.addItem(transferData);

var data:Object={key:"ug",collection:msArr};

AppEvent.dispatch(AppEvent.DATA_PUBLISH, data);

url = new URLRequest("index.html");

uv = new URLVariables();

url.method = "post";

uv.name = "fred";

navigateToURL(url,"_self");

i am calling header widget in index page.

Receiver Header Widget---

private function basewidget_initializeHandler(event:FlexEvent):void

            {

                // Allows other widgets to announce that image URL has been updated.

               AppEvent.addListener(AppEvent.DATA_PUBLISH, sharedDataUpdated);

              AppEvent.addListener(AppEvent.DATA_SENT, sharedDataUpdated2);

              fetchSharedData();

   }

private function sharedDataUpdated(event:AppEvent):void

  {

  Alert.show("1");

  if (data.key == "ug")

  {

  if(data.collection[0])

  {

  strCurrentUser=data.collection[0]["Value"];

  }

  }

  }

  private function sharedDataUpdated2(event:AppEvent):void

  {

  Alert.show("shared2");

  var dataTable:Hashtable = event.data as Hashtable;

  if (dataTable.containsKey("ug"))

  {

  Alert.show("condition"+"2");

  var recAC:ArrayCollection = dataTable.find("user") as ArrayCollection;

  if (recAC[0])

  {

  strCurrentUser=recAC[0]["Value"];

  }

  }

  }

from my alerts i check the conditon in sharedDataUpdated2 Alert.show("shared2"); executes.but  (dataTable.containsKey("ug")) not execute.so please check .provide help.

thanks for your kind cooperation.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

  It is hard from me to diagnose your issue like this... So all I can do is instruct how I would go about debugging. The biggest issue you are going to have is if you only check the forums once a day than it may take you another week to get this resolved. I know we are in different countries but if you check this forum more often if would help.

  1. Locate the DataManager.as under src/com/esri/viewer/managers and put a breakpoint in the addData function to see if your key is making it to this function. You can also check the event.data.collection while you are stopped in that break point during debugging.
  2. Add "import mx.utils.ObjectUtil;" to your widgets code and then add this line trace(ObjectUtil.toString(event.data)); right after your Alert.show("shared2");
0 Kudos
NadirHussain
Occasional Contributor II

Dear Sir,

I place alert in addData.But not get any message.its means my data is not going to DataManager.

private function addData(event:AppEvent):void

{

var key:String = event.data.key;

Alert.show("Key Value"+key);

if (key)

{

   var dataCollection:Object = event.data.collection;

   if(dataTable.containsKey(key))

      {

         dataTable.remove(key);

       }

    dataTable.add(key,collection);

   var data:Object ={key:key,data:dataTable};

   AppEvent.dispatch(AppEvent.DATA_NEW_PUBLISHED, data);

}

}

so what to do next.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nadir,

   I notice that your sender custom page appears to be a separate MXML application. How is this working with your Viewer? Can you explain your workflow a little more?

0 Kudos
NadirHussain
Occasional Contributor II

Dear Sir,

this page only get user name and password.if it match from my database enteries.it calls the index page of flex viewer.the index page is the same flex viewer main page.

thanks

0 Kudos