how to use request parameter with special character in HTTPService - Flex - apache-flex

Currently I have :
<mx:HTTPService id="userLogin" url="https://api.localhost/api/user/login/" method="POST" resultFormat="e4x" result="doSomeThing(event)">
<mx:request>
<email>{loginUser}</email>
<password>{loginPassword}</password>
</mx:request>
</mx:HTTPService>
instead of this I have params like userCredentials.email and userCredentials.password.
I tried this but it odesnt work.
<mx:HTTPService id="userLogin" url="https://api.localhost/api/user/login/" method="POST" resultFormat="e4x" result="doSomeThing(event)">
<mx:request>
<userCredentials.email>{loginUser}</userCredentials.email>
<userCredentials.password>{loginPassword}</userCredentials.password>
</mx:request>
</mx:HTTPService>

let us know if its work for you:
<mx:HTTPService id="userLogin" url="https://api.localhost/api/user/login/" method="POST" resultFormat="e4x" result="doSomeThing(event)">
<mx:request>
<userCredentials>
<email>{loginUser}</email>
<password>{loginPassword}</password>
</userCredentials>
</mx:request>
</mx:HTTPService>
also did you see this from http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_5.html :
<?xml version="1.0"?>
<!-- fds\rpc\WebServiceSOAPRequest.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" verticalGap="10">
<mx:WebService id="ws" wsdl="http://api.google.com/GoogleSearch.wsdl"
useProxy="true">
<mx:operation name="doGoogleSearch" resultFormat="xml">
<mx:request format="xml">
<ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<key xsi:type="xsd:string">XYZ123</key>
<q xsi:type="xsd:string">Balloons</q>
<start xsi:type="xsd:int">0</start>
<maxResults xsi:type="xsd:int">10</maxResults>
<filter xsi:type="xsd:boolean">true</filter>
<restrict xsi:type="xsd:string"/>
<safeSearch xsi:type="xsd:boolean">false</safeSearch>
<lr xsi:type="xsd:string" />
<ie xsi:type="xsd:string">latin1</ie>
<oe xsi:type="xsd:string">latin1</oe>
</ns1:doGoogleSearch>
</mx:request>
</mx:operation>
</mx:WebService>
</mx:Application>
i mean this mx:request structure?

Related

Flex viewstack children includeIn works funny

I have a viewstack with childrens which I want to show/hide depending on the state the application is
<?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"
xmlns:eworx="com.eworx.*"
xmlns:view="com.eworx.view.*"
xmlns:components="com.eworx.view.components.*"
skinClass="com.eworx.view.skins.MainAppSkin"
xmlns:layouts="com.eworx.view.layouts.*"
currentState="login"
initialize="init(event)"
creationComplete="complete(event)"
width="100%"
height="100%">
<fx:Style source="assets/css/screen.css" />
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import nl.demonsters.debugger.MonsterDebugger;
private var debugger:MonsterDebugger;
[Bindable]
public var apiUrl:String;
[Bindable]
public var customerType:String;
protected function init(event:FlexEvent):void
{
debugger = new MonsterDebugger(this);
}
protected function complete(event:FlexEvent):void
{
var activated:Boolean = FlexGlobals.topLevelApplication.parameters.activated;
var passwordReset:Boolean = FlexGlobals.topLevelApplication.parameters.passwordReset;
var message:String = FlexGlobals.topLevelApplication.parameters.message;
apiUrl = FlexGlobals.topLevelApplication.parameters.apiUrl;
if(activated)
{
Alert.show(message,"Notice");
}
if(passwordReset)
{
Alert.show(message,"Notice");
}
systemManager.addEventListener(MouseEvent.MOUSE_WHEEL,onMouseWheel,true);
}
private function onMouseWheel(e:MouseEvent):void
{
e.delta *= 5;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<eworx:Seven7Context contextView="{this}" />
<s:Fade id="fadeIn" alphaFrom="0" alphaTo="1" duration="300" />
<s:Fade id="fadeOut" alphaFrom="1" alphaTo="0" duration="300" />
<s:Rotate3D id="r3d" angleYFrom="0" angleYTo="360" duration="300" />
</fx:Declarations>
<s:states>
<s:State name="login" />
<s:State name="wholesale" />
<s:State name="retail" />
</s:states>
<view:LoginForm id="loginForm" includeIn="login" horizontalCenter="0" verticalCenter="0" />
<s:Group excludeFrom="login" width="960" horizontalCenter="0">
<s:BitmapImage width="100%" height="42" x="13" y="80" source="#Embed('assets/garnish/bar.png')" />
<mx:Image source="assets/garnish/logo.png" top="23" />
<s:HGroup verticalAlign="middle" x="198" y="47">
<s:TabBar skinClass="MainMenuTabBarSkin" dataProvider="{vs}" buttonMode="true"/>
<mx:LinkButton id="logout" label="Logout" click="{currentState='login'}" />
</s:HGroup>
<s:HGroup top="0" right="0" gap="1" verticalAlign="top">
<components:OfferList />
<components:MarginBuildersTrack />
<components:CartTrack top="0" />
</s:HGroup>
<mx:ViewStack
id="vs"
top="120"
horizontalCenter="0"
width="960"
height="100%"
resizeToContent="true" >
<view:HomePage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="Home" />
<view:ShowroomPage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="Showroom" />
<view:CataloguePage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="Catalogue" />
<!--<view:IncentivesPage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="Incentives" />-->
<view:RetailCustomerProfilePage includeIn="retail" showEffect="{fadeIn}" hideEffect="{fadeOut}" label="My Profile" />
<view:WholesaleCustomerProfilePage includeIn="wholesale" showEffect="{fadeIn}" hideEffect="{fadeOut}" label="My Profile" />
<view:ClientsPage excludeFrom="retail,login" showEffect="{fadeIn}" hideEffect="{fadeOut}" label="My Clients" />
<view:CartPage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="My Cart" />
<view:OrdersPage showEffect="{fadeIn}" hideEffect="{fadeOut}" label="My Orders" />
</mx:ViewStack>
</s:Group>
</s:Application>
AS you can see I inlude the retail customer view in the retail state and the wholesale customer view in the wholesale state. The problem is that when I run my app they don't appear on neither state.
Any ideas?
This is an odd approach to me. The whole purpose of the ViewStack is to only show one item at once. This is a very odd approach.
I see you have a tabbar whose dataProvider is the ViewStack. However, your ViewStack is not created as a bindable property on the component, and you never seem to set up an initial state. So, I theorize that this is happening:
App Loads in default state, which is the empty string
ViewSTack and/or TabBar are initialized without those children
App state changes for some reason
TabBar does not update
CreationPolicy may come into play too, but I'm not sure. You'll have to step through the code to figure out what's going on. I would strongly recommend you consider an alternate approach to this. Possibly creating the tabbar navigator dataProvider manually based on user security settings or the current state.

Creating a TreeGrid with sortable columns

I'd like to put a TreeGrid in my application so that the columns can be sorted. If you refer to this sample application, you'll notice that if you
Open a branch node
Sort by one of the columns
Close that branch node
then the TreeGrid starts to get out of wack and duplicate columns start appearing and other columns start disappearing. What I would like is to have the columns sorted only by the outermost nodes.
One attempt I had was to run treeGrid.closeAllItems() before the sort occurred. However, this does not work, because a Sort Column event gets dispatched while closeAllItems is running, so the list gets messed up and listOutOfBounds exceptions get thrown.
Has anyone had any success with this, or have any ideas?
Here is a piece of working code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.HierarchicalData;
]]>
</mx:Script>
<mx:XMLList id="dataProviderXMLList">
<node id="1" name="Companies" type="COMPANIES" desc="All Companies" statusIcon="statusIcon">
<node id="2" name="Adobe" type="COMPANY" desc="Adobe inc." statusIcon="statusIcon">
<node id="5" name="Adobe Consulting" type="COMPANY" desc="Adobe (formerly macromedia)" statusIcon="statusIcon" />
<node id="6" name="EDBU" type="COMPANY" desc="Database company" statusIcon="statusIcon" />
</node>
<node id="3" name="Macromedia" type="COMPANY" desc="Adobe (formerly macromedia)" statusIcon="statusIcon" />
<node id="4" name="Oracle" type="COMPANY" desc="Database company" statusIcon="statusIcon" />
</node>
</mx:XMLList>
<mx:AdvancedDataGrid width="100%" height="100%" sortExpertMode="true" id="adg1" designViewDataType="tree" dataProvider="{new HierarchicalData(dataProviderXMLList)}">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Companies" dataField="#name"/>
<mx:AdvancedDataGridColumn headerText="COMPANIES" dataField="#type"/>
<mx:AdvancedDataGridColumn headerText="All Companies" dataField="#desc"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
Bu this is using AdvancedDataGrid and it works perfectly fine.

Flex Combobox: how to get the value of the selected item?

I am using a combobox for the us states, link. The label is set to the full name of the state, while the value attribute holds the abbreviation. What I want to do is to get the selected item's value. So I tried combo.selectedItem.value and combo.selectedItem.#value, but neither of them worked. Can someone shed a light on this please?
Here's a simple example that might be helpful.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:ComboBox id="comboBox" dataProvider="{[{label:'California', value:'CA'}, {label:'New York', value:'NY'}]}" />
<mx:Label text="{comboBox.selectedItem.value}" />
</mx:Application>
Here's another example. In this one we use XML as dataProvider.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:XML id="xml" xmlns="">
<states>
<state label="Alabama" value="AL" country="US" />
<state label="Alaska" value="AK" country="US" />
<state label="Arkansas" value="AR" country="US" />
</states>
</mx:XML>
<mx:ComboBox id="comboBox" dataProvider="{xml.state}" labelField="#label" />
<mx:Label text="{comboBox.selectedItem.#value}" />
</mx:Application>
You can populate an array with the values you want to get and retrieve the index of the selected item on the combo box (which should be the same as in the array).
Or in your component ... just look for the index (selected item) child on statesUS

Problem with HTTPService's send method

<mx:HTTPService id="myService" url="configure.php" method="POST">
<mx:request xmlns="">
<mode>
{modeLabel.text}
</mode>
</mx:request>
</mx:HTTPService>
<mx:Button label="Start" id="startButton" click="{myService.send()}" width="88" height="38" x="52" y="36"/>
The above code works fine i.e. the service gets started and the configure.php does it's work but instead of using click="{myService.send()}", if I use a function call (as done in following code) the service does not get started or configure.php does not perform it's work.
<mx:Script>
<![CDATA[
private function start():void
{
startButton.enabled = false;
myService.send();
}
]]>
</mx:Script>
<mx:Button label="Start" id="startButton" click="start()" width="88" height="38" x="52" y="36"/>
Any idea why the service not executing when invoked from a function?
Thanks
That should be working but you can try to remove the <mx:request> block and instead do this:
myService.send({mode: modeLabel.text});

Binding effect properties inside effect tags not working?

We're trying to do this:
<rollOverEffect>
<AnimateProperty property="scaleX" toValue="{originalWidth + scaleFactor}" />
</rollOverEffect>
However, it seems as though the effects toValue is always NaN. If I set the value to a constant the effect works. Isn't it possible to use databinding for effects like this?
Addendum:
Both originalWidth and scaleFactor is bindable. I managed to get this working by moving the effect out of the rollOverEffect-tag, giving it and id and then binding to it like so:
<AnimateProperty id="scaleEffect" property="scaleX" toValue="{originalWidth + scaleFactor}" />
<MyComponent rollOverEffect="{scaleEffect}" />
Any idea why this works and the former code doesn't? The latter snippet creates a second, uneccessary binding and isn't as readable, but at least it works.
Addendum:
The following code highlights the problem. No matter what the slider is set to, the value of the angleTo property of the effects will always be set to whatever the sliders initial value is set to.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:Label text="Rotation (mouse over on canvas triggers effect):" />
<mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />
<mx:Spacer height="50" />
<mx:Canvas borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200">
<mx:rollOverEffect>
<mx:Rotate angleTo="{slider.value}" duration="500" />
</mx:rollOverEffect>
<mx:rollOutEffect>
<mx:Rotate angleTo="{-slider.value}" duration="500" />
</mx:rollOutEffect>
</mx:Canvas>
</mx:VBox>
</mx:Application>
Compare the with the following code which actually produces the expected result:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Rotate id="rollOver" angleTo="{slider.value}" duration="500" />
<mx:Rotate id="rollOut" angleTo="{-slider.value}" duration="500" />
<mx:VBox horizontalCenter="0" verticalCenter="0">
<mx:Label text="Rotation (mouse over on canvas triggers effect):" />
<mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />
<mx:Spacer height="50" />
<mx:Canvas rollOverEffect="{rollOver}" rollOutEffect="{rollOut}" borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200" />
</mx:VBox>
</mx:Application>
So essentially what the question is, why doesn't the binding work in the first example? There are no errors or warnings to tell you this and neither can I find anything in the documentation about this, could it be a bug?
You need to show us more code. Can you give the following code a shot? Does this work?
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<!-- Simple exemplo to demonstrate the AnimateProperty effect. -->
<mx:Sequence id="animateScaleXUpDown" >
<mx:AnimateProperty property="scaleX" fromValue="{ns.value}" toValue="{ns.minimum}" duration="1000" />
<mx:AnimateProperty property="scaleX" fromValue="1.5" toValue="1" duration="1000" />
</mx:Sequence>
<mx:Panel title="AnimateProperty Effect Example" width="75%" height="75%"
paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
<mx:Text width="100%" color="blue"
text="Click on the image to use the AnimateProperty effect with the scaleX property."/>
<mx:Image id="flex" source="http://stackoverflow.com/content/img/stackoverflow-logo.png"
mouseDownEffect="{animateScaleXUpDown}"/>
<mx:NumericStepper id="ns" width="62" value=".5" minimum="1" maximum="3" stepSize="0.5" enabled="true"/>
</mx:Panel>
</mx:Application>

Resources