Link to home
Start Free TrialLog in
Avatar of thebellman
thebellmanFlag for United States of America

asked on

How do I send values in datagrid to server using actionscript

I'm relatively new to Flex.  I have a small sample application running that is receiving/sending data from a server and populating components.

 I'm having problems sending the values from a datagrid (could be a list) to the server.  I tried a form, but I can't seem to get the form to post to the server.  The error handler executes before reaching the server.  I don't have to use a form, but I thought it was going to be the easiest method.  
.........
 
This is the function I have setup to send the data.  I'm trying to send the values in the data grid, "selectedvalues" to the server.
 
I suspect I'm missing a simple concept... I hope.
 
Thanks!
 
private function saveRequest():void
				{
					saveHttp = new HTTPService();
					CursorManager.setBusyCursor();
varHttp.url = "http://bl-ux-ssd1.na.dir.bunge.com:9080/SASStoredProcess/do?_program=SBIP%3A%2F%2FFoundation%2FBIP+Tree%2FUsers%2Fcjobell%2Flimit_test2%28StoredProcess%29&_action=strip&_debug=&_selection=" ;
					saveHttp.method = "GET";  
					saveHttp.addEventListener("result", saveRuleHandler);
                	saveHttp.addEventListener("fault", limFaultHandler);
					saveHttp.send(parameters);
					
					
				}			
				
				
			private function limFaultHandler(event:FaultEvent):void{
				CursorManager.removeBusyCursor();	
				Alert.show("There was a problem","Error");
			}
			
			private function limResultHandler(event:ResultEvent, token:AsyncToken):void{
				limitvars = event.result.row;	
				CursorManager.removeBusyCursor();		
			}
			private function varResultHandler(event:ResultEvent, token:AsyncToken):void{
				resvars = event.result.row;	
				CursorManager.removeBusyCursor();		
			}
			
			private function saveRuleHandler(event:ResultEvent):void{
							CursorManager.removeBusyCursor();		
			}
			
		]]>
		
		
	</mx:Script>
	 
	 <mx:ArrayCollection id="limitvars2" source="{ArrayUtil.toArray(limitvars)}"/>
	
	 
 
	<mx:ViewStack x="41.5" y="47" id="viewstack1" width="692" height="402" cornerRadius="20">
		<mx:Panel label="Title" width="100%" height="100%" backgroundColor="#FBF6F6" cornerRadius="20" backgroundAlpha="0.49">
			<mx:Text text="Limit Manager" width="205" x="10" y="45" fontSize="16"/>
			<mx:HBox width="662" height="142" backgroundColor="#FCF9F9" cornerRadius="20" backgroundAlpha="0.02" horizontalAlign="center" verticalAlign="bottom">
				<mx:TextArea width="600" height="97" wordWrap="true" editable="false" enabled="true" alpha="0.0" backgroundAlpha="0.0">
					<mx:text><![CDATA[The limit manager allows you to create groups of limit rules.  Each limit rule is comprised of a set of instructions for reporting limit violations.  This wizard will take you through the steps of createing a limit rule set(s).
						 ]]>
</mx:text>
				</mx:TextArea>
			</mx:HBox>
		</mx:Panel>
		<mx:Panel label="Step 2"  width="100%" height="100%" layout="absolute"  title="Limit Rule Wizard" fontSize="12">
			<mx:ComboBox 	x="204" y="38" id="limvars" dataProvider="{limitvars}"
							prompt="Please select a variable"
							width="295"
							editable="false"
							close="getlimvarvalues(event);">
			</mx:ComboBox>
			<mx:DataGrid x="191" y="96" height="193" dataProvider="{resvars}"  dragEnabled="true" dragMoveEnabled="true" width="137">
				<mx:columns>
					<mx:DataGridColumn dataField="data" headerText="Unique values" />
				</mx:columns>
			</mx:DataGrid>
				
			
			<mx:Text x="10" y="99" text="Part B. Drag the desired values to the selected list" width="173" height="65"/>
			<mx:Text x="10" y="10" text="Part A. Select a variable for the limit rule set"/>
			
			<mx:Form x="368" y="79" width="282" height="262">
				<mx:DataGrid height="193" id="selectedvalues" dropEnabled="true" dataProvider="[]" width="137">
					<mx:columns>
						<mx:DataGridColumn  headerText="Selected values" dataField="data"/>
					</mx:columns>
					
				</mx:DataGrid>
				<mx:FormItem label="Save the limit rule set">
					<mx:Button label="Save it!" click="saveRequest();"/>
				</mx:FormItem>
			</mx:Form>
		</mx:Panel>
		<mx:Panel label="Step 2" width="100%" height="100%" >
		</mx:Panel>

Open in new window

Avatar of Fuzzy_Logic_
Fuzzy_Logic_
Flag of United Kingdom of Great Britain and Northern Ireland image

You probably know this but just in case

From AdobeLiveDocs:

send      ()      method       
public function send(parameters:Object = null):AsyncToken

Executes an HTTPService request. The parameters are optional, but if specified should be an Object      containing name-value pairs or an XML object depending on the contentType.

Parameters
      parameters:Object (default = null)  An Object containing name-value pairs or an XML object, depending on the content type for service requests.

Returns
      AsyncToken  An object representing the asynchronous completion token. It is the same object available in the result or fault event's token property.



Charles is also a useful tool, especially in this case: http://www.charlesproxy.com/ ( bizarrely I've just recommended this tool to someone else )

Regards

FL
Avatar of thebellman

ASKER

Thank you for the response - the link to Charles was worth everything! - Great application!!!!

I'm going to show my lack of knowledge on flex...

I thought that was the right way to accomplish it.  However, I still couldn't get it to pass the parms.  This is what I originally had in my request.   Do I need to step through the grid to build an array?


I would except that the data from the grid be passed on the url as a parameter.  
private function saveRequest():void
				{
					var parms:Object = new Object();
					parms.tags=selectedvalues.data;
					
					saveHttp = new HTTPService();
					CursorManager.setBusyCursor();
saveHttp.url = "http://bl-x-ssd1.na.dir.bunge.com:9080SASStoredProcess/" ;
					var responder:ItemResponder = new ItemResponder(saveRuleHandler, limFaultHandler);
					var token:AsyncToken = saveHttp.send(parms);
					token.addResponder(responder);
					saveHttp.resultFormat="e4x"		
				}			

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fuzzy_Logic_
Fuzzy_Logic_
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks - For any one with a similar issue -

I added this one line:

var dgList:ArrayCollection = this.selectedvalues.dataProvider as ArrayCollection;

and sent the parameters:
var token:AsyncToken = saveHttp.send(dgList);

it works.!